python - Django self referencing model filter ForeignKey -


say have following model in django:

class category(models.model):     parent = models.foreignkey('self', null=true, blank=true) 

is there way prevent referencing same category? right django generates select field in admin area im able select same category parent. there way filter select in admin?

use foreignkey.limit_choices_to - see documentation here

you haven't provided enough of code snippet see how done in case, i'm guessing on parent foreignkey, you'd want limit choices lambda function checks see if name of category same 1 doing referencing.

you want lambda function here, not single expression.


Comments

Popular posts from this blog

windows - Single EXE to Install Python Standalone Executable for Easy Distribution -

c# - Access objects in UserControl from MainWindow in WPF -

javascript - How to name a jQuery function to make a browser's back button work? -