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 a queryset of 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 no iteration > contained in the method - you iterate through your existing queryset > 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. -- 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.