I have a similar challenge and I think that I shall tackle it by making the 
first level dependency outside the main model, i.e. Building should be a 
ForeignKey in BuildingOwner model.  Then your main model shouldn’t have the a 
link to the Building model, but rather 2 ForeignKeys to BuildingOwner. Seems 
logical, but will it work?

Bruckner
0836251086

> On 01 Nov 2019, at 00:54, J-23 <bacze...@poczta.fm> wrote:
> 
> 
> Hello,
> I am new to Django. I have a FormFault model, which has two foreign keys 
> "BuildingOwner" and "Building", the key "Building" depends on "BuildingOwner" 
> on the form, it gives me two fields of type Select (ComboBox) or is there a 
> way in Django that the content of ComboBox changes depending on 
> "BuildingOwner" values?
> 
> from django.db import models
> 
> class Items(models.Model):
>     Item_Text = models.CharField("Temat", max_length=100)
> 
>     def __str__(self):
>         return self.Item_Text
>     
> 
>     class Meta:
>          verbose_name = "Temat zgłoszenia"
>          verbose_name_plural = "Temat zgłoszeń"
> 
> class DocumentType(models.Model):
>     Document_Text = models.CharField("Rodzaj", max_length=100) 
> 
>     def __str__(self):
>         return self.Document_Text
>     
>     class Meta:
>         verbose_name = "Rodzaj zgłoszenia"
>         verbose_name_plural = "Rodzaj zgłoszeń"
> 
> class Status(models.Model):
>    Status_Text = models.CharField("Status", max_length=100)
> 
>    def __str__(self):
>       return self.Status_Text
> 
>    class Meta:
>       verbose_name = "Status zgłoszenia"
>       verbose_name_plural = "Status zgłoszeń"
> 
> class BuildingOwner(models.Model):
>     BuildingOwner_Text = models.CharField("Właściciel", max_length=100)
> 
>     def __str__(self):
>       return self.BuildingOwner_Text
> 
>     class Meta:
>       verbose_name = "Właściciela budynku"
>       verbose_name_plural = "Właściciel budynków"
> 
> class Building(models.Model):
>     BuildingOwner = models.ForeignKey(BuildingOwner, verbose_name="Właściciel 
> budynku", on_delete=models.CASCADE)
>     Building_Text = models.CharField("Budynek", max_length=150)
>   
>     def __str__(self):
>       return self.Building_Text
> 
>     class Meta:
>       verbose_name = "Budynek"
>       verbose_name_plural = "Budynki"
> 
> class FormFault(models.Model):
>     Person = models.CharField("Imię i Nazwisko",max_length=300)
>     Email = models.EmailField("E-mail", max_length=50)
>     Items = models.ForeignKey(Items, verbose_name="Temat", 
> on_delete=models.CASCADE)
>     DocumentType = models.ForeignKey(DocumentType, verbose_name="Rodzaj 
> dokumentu", on_delete=models.CASCADE)
>     Status = models.ForeignKey(Status, on_delete=models.CASCADE)
>     BuildingOwner = models.ForeignKey(BuildingOwner, verbose_name="Właściciel 
> budynku", on_delete=models.CASCADE)
>     Building = models.ForeignKey(Building, verbose_name="Budynek", 
> on_delete=models.CASCADE)
>     Place = models.CharField("Lokal", max_length=10)
> 
>     class Meta:
>          verbose_name = "Zgłoszenie"
>          verbose_name_plural = "Zgłoszenia"
> 
>     
> 
> 
> 
> 
> I found a library here: 
> https://github.com/runekaagaard/django-admin-flexselect
> 
> but I'm wondering if this can't be done in a simpler way.
> 
> Best regards,
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Django users" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to django-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-users/1c2bd867-91b3-4434-9604-08eca8e7b8b1%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/1C1B35E1-7F5A-4D57-86ED-F0C6A2212758%40gmail.com.

Reply via email to