python - Define a django model which use in a foreign key a specific instance of an other model -


let's take example problem : models of blog. have django models :

class category(models.model):     name = models.charfield(max_length=30)  class article(models.model):     title = models.charfield(max_length=30)     content = models.textfield()     category = models.foreignkey('category') 

my problem how define other model use specific category. example, how define cook model, based on article model inheritance, used category 'cook'.

thank you.

to complete comment:

class category(models.model):     name = models.charfield(max_length=10)  def cook_category():     return category.objects.get(name='cook')  class cookarticle(models.model):     #your model     category = models.foreignkey(category, default=cook_category) 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -