I kinda came across an article about creating Proxy Models, that is what I tried and it really seemed to do what I needed, pretty cool. Here is what I coded ...(sorry for the formatting, if it looks goofy)
Edit “models.py” file: (create the new Proxy Model) class RequestTicketCompleted(RequestTicket): class Meta: proxy=True verbose_name = ‘Request Tickets Completed’ verbose_name_plural = ‘Request Tickets Completed’ def days_old(self): return self.completion_date – self.issued_date days_old.short_discription = ‘Days Old’ Edit “admin.py” file: class RequestTicketCompletedAdmin(RequestTicketAdmin): def queryset(self, request): qs = super(RequestTicketAdmin, self).queryset(request) if request.user.is_superuser: return qs.filter(completion_date__isnull=False) def save_model(self, request, obj, form, change): obj.user = request.user obj.save() admin.site.register(RequestTicketCompleted, RequestTicketCompletedAdmin) now that shows up on my main admin page under the my application section, the superuser can see it, click on it and it will only display the completed tickets, with the amount of days it took to complete, then they can also click on the plain Request Tickets and see any open tickets by all users/techs and how long they have been open for, sweet. I had also read where it could be setup as a default manager on the proxy to provide custom queryset instead of in the admin class, so i will try and look into do that. The only thing is that it will not show up on the list of Permissions to be able to assign to users who would like to see closed tickets as well, but that is not a really big deal. Thanks for all your help On Oct 24, 9:12 am, eyscooby <kenneyschm...@hotmail.com> wrote: > So with the items that are still waiting to be complete i wanted to > show how many days the ticket has been open by doing something > like ... > > return date.today() - self.issued_date > > and then those that are complete ... > > return self.competion_date - self.issued_date > > Can i create 2 managers for this?? one to return completed, and one to > return not completed?? > > On Oct 18, 12:04 pm, eyscooby <kenneyschm...@hotmail.com> wrote: > > > > > Ok, this is helping, believe it or not your are helping, I'm probably > > confusing myself mostly. > > > So the model method explanation was very helpful and you are correct > > that works great, as long as all dates have a completion_date. If a > > new ticket is entered it will fail due to a "NoneType field with > > DateField". > > That line in my model is as such "completed_date = > > DateField(blank=True, null=True)". > > > The Manager is doing nothing more than returning data from the > > database as a query so that makes sense also. > > > Step two .. is it because of the NULL=True? can't subtract date field > > from null field (which makes sense), is there a way around that? > > I think this is why i was trying to calculate on a specific filter. > > > On Oct 18, 3:47 am, Daniel Roseman <dan...@roseman.org.uk> wrote: > > > > On Monday, 17 October 2011 20:28:47 UTC+1, eyscooby wrote: > > > > > Ok, sorry I thought I was starting to understand it a little better, > > > > but now I think I took a step backwards, so if it is ok with you let's > > > > step back and take it a step at a time. > > > > > So, my first step is wondering if I really need a manager or not?? > > > > I was thinking from your first response to me that you might be > > > > suggesting that I did. Let's start there. > > > > If I understand it correctly the Manager is a way of retrieving > > > > specific information. > > > > > thanks > > > > Sorry for confusing you. There are two things going on here. > > > > A Manager is for making custom queries to the database, to return new > > > objects - either one or aquerysetof many. Your original code was using > > > `Model.filter()` and modifying the result, so I suggested that it belonged > > > in a manager. > > > > A model method is useful when you want to do a separate, non-database, > > > operation on a single object. That's what you really want to do here - > > > given > > > an instance of RequestTicket, calculate how old it is. There's noiteration > > > contained in the method - you iterate through your existingqueryset > > > elsewhere (say in the template) and call days_old on each instance: > > > > {% for ticket in completed_tickets %} > > > {{ ticket.name }}: {{ ticket.days_old }} > > > {% endif %} > > > > Or, in your particular circumstance, you simply give the `days_old` method > > > as one of the elements of the `list_display` tuple, and Django takes care > > > of > > > the iterating, calling `days_old` on each row in the changelist. > > > > So in both of these circumstances, `days_old` simply needs to look like > > > this: > > > > def days_old(self): > > > return self.competion_date - self.issued_date > > > > - so it returns a single value, for the one particular ticket instance > > > which > > > it has been called on. > > > > Hope that helps. > > > -- > > > DR.- Hide quoted text - > > > - Show quoted text -- Hide quoted text - > > - Show quoted text - -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.