2

New to django - trying to get smart_selects working but the dropdown fields don't seem to be populating on the form.

I've trawled the web for answers and read the few similar questions on stackoverflow but none suggest a working answer for the smart_selects app.

My data model: multiple catalogues in a DMU, and multiple DMUs in a single survey. Currently the Survey select is populated but the DMU and catalogue options are not. Any help would be much appreciated.

model.py

class Survey(models.Model):
survey = models.CharField(max_length=40, default='GAMA')
def __str__(self):
    return self.survey

class DMU(models.Model):
    dmu = models.CharField(max_length=40, default='GroupFinding')
    survey = models.ForeignKey(Survey)
    CHOICES=(
        ('sm', 'stellarmasses'),
        ('gf', 'groupfinding'),
    )
    def __str__(self):
        return self.dmu

class Catalogue(models.Model):
    catalogue = models.CharField(max_length=40, default='GalG3C')
    dmu = models.ForeignKey(DMU)
    def __str__(self):
        return self.catalogue

class allData(models.Model):
    catalogue = models.ForeignKey(Catalogue)
    dmu = ChainedForeignKey(DMU, chained_field='catalogue', chained_model_field='catalogue', auto_choose=True)
    survey = ChainedForeignKey(Survey, chained_field='dmu', chained_model_field='dmu', auto_choose=True)
    def __str__(self):
        return '%s %s %s' % (self.survey, self.dmu, self.catalogue)

forms.py

class ASVOForm(forms.ModelForm):
    class Meta:
        model=allData
        fields = '__all__'
Liz
  • 1,421
  • 5
  • 21
  • 39
  • Either your textual explanations of the relationship or your models are wrong. It's not the same. In your code, each `Catalogue` has multiple `DMU`s and each `DMU` has multiple `Survey`s. Is this correct? – Martol1ni Sep 11 '15 at 13:04
  • Ah. It should be that each catalogue is assigned to a single dmu and each dmu is assigned to a single survey. I'm new to django so help with the models would be appreciated! (Survey contains multiple dmus, each of which contain multiple catalogues). – Liz Sep 12 '15 at 23:59
  • I think I've corrected it (see edit) – Liz Sep 13 '15 at 04:55
  • regardless, the dropdowns are still not populating :( – Liz Sep 13 '15 at 04:58

0 Answers0