dimanche 20 décembre 2015

django foreign keys object set with inspectdb

I have a legacy mysql database. using th inspectdb command I created a model for that database and added ForeignKey's manually. the problem is that django wont create object sets for those keys (many to one relation) like it would for regular django model.

class Seller(model.models):
     name = models.charField(...)

class Customer(model.models):
     name = models.charField(...)
     seller_id = models.ForeignKey(Seller)

and what i want to do is:

s = Seller.objects.all()[0]
s.customer_set.all()

but django throws an error that the object has no attribute.

thanks!

p.s

the code above is an example for what I want to happen with the legacy database.




Aucun commentaire:

Enregistrer un commentaire