I have a problem connecting custom methods in my model I found a solution in the Django Book but it does not work My code for here is
class news manager (model manager): def millistine news (self): return self. Object. Order Bibi ('- id') [: 3] Class News (model model): title = model. SloughField () shortBody = models.CharField (max_length = 250) fullBody = models.TextField () Author = Model. Förnegyi (user)
And now I run python manage.py shell
and import it from
news.models * News .objects.getLastNews () ... attribute error manager object does not have any attributes GetLastNews
Where did I make a mistake?
Is BTW a good way to get information from this model and is going to see it?
You must associate the manager with the model:
class news (Models.Model): #. Objects = news manager ()
And yes, this is a great way to add "table-level" functionality to your model.
Comments
Post a Comment