how to create instant of models in mdoels.py class django code example
Example 1: get_absolute_url django
def get_absolute_url(self):
from django.core.urlresolvers import reverse
return reverse('', kwargs={'pk': self.pk})
Example 2: str django
def __str__(self):
return self.name
Example 3: how to get foregine kew field in models.py
items = CartItem.objects.select_related('product').filter(cart=cart)