class Topping(models.Model):
some = models.CharField(max_length=30)
class Pizza(models.Model):
name = models.CharField(max_length=50)
toppings = models.ForeignKey(Topping, on_delete=models.SET_NULL )
def __unicode__(self):
return u"%s (%s)" % (self.name, u", ".join([topping.name
for topping in self.toppings.all()]))
как получить toppings__some?
q = queryset.model.objects.all()
fields = q.model._meta.get_fields()
for x in fields:
#if isinstance(x, ForeignKey):
# zzz = q.model._meta.get_field(x.name)
print(x.name) # получаем toppings, как получить name?