1👍
✅
You can use limit_choices_to=…
[Django-doc] to filter the items for the ForeignKey
, so:
class Registration(models.Model):
room = models.ForeignKey(
Room,
on_delete=models.CASCADE,
limit_choices_to={'room_bool': True},
verbose_name='Номер',
help_text='Номер в который хотите заселить гостя!'
)
# …
Note: normally a Django model is given a singular name, so
Room
instead of.Rooms
Source:stackexchange.com