Friday, November 1, 2019

Re: Field Select MasterDetail

Check django-autocomplete light.


On Friday, November 1, 2019 at 4:25:06 AM UTC+5:30, J-23 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: 

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+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/11976e3d-d65e-4b2e-9e42-8a0c7c6a0f04%40googlegroups.com.

No comments:

Post a Comment