jrief / django-formset

The missing widgets and form manipulation library for Django
https://django-formset.fly.dev/
MIT License
326 stars 35 forks source link

pre select - state - example #49

Closed sasikumar1978k closed 1 year ago

sasikumar1978k commented 1 year ago

when i try to implement in my model object i got this error

[25/Mar/2023 10:01:59] "GET /office_add_view/undefined?offset=0&filter-Class_code=11&field=undefined HTTP/1.1" 200 6984

Please help what wrong in this code

class ClassDet(models.Model):

Class_code = models.CharField(max_length = 4,unique=True)
Class_name = models.CharField(max_length = 4)
def __str__(self):
    return self.Class_name

class GroupCode(models.Model):

Group_code = models.CharField(max_length = 4)
Group_name = models.CharField(max_length = 300)
Class_code = models.ForeignKey('ClassDet', on_delete=models.CASCADE)
class Meta:
    unique_together = ('Group_code','Class_code',)

def save(self, *args, **kwargs):
    for field_name in ['Group_code','Group_name',]:
        val = getattr(self, field_name, False)
        if val:
            setattr(self, field_name, val.upper())
    super(GroupCode, self).save(*args, **kwargs)
def __str__(self):
    return self.Group_code + '-' + self.Group_name

class GroupSubject(models.Model):

Class_code = models.ForeignKey(ClassDet, on_delete=models.SET_NULL, null=True)
Group_code =  models.ForeignKey(GroupCode, on_delete=models.SET_NULL, null=True)

class Meta:
    unique_together = ('Class_code', 'Group_code','subject_code')

form

Group_code = forms.ModelChoiceField( queryset=GroupCode.objects.all(), widget=Selectize(

        filter_by={"Class_code" : "Class_code_id"},
    ),
    required=False,
)
sasikumar1978k commented 1 year ago

in Browser console Uncaught (in promise) SyntaxError: JSON.parse: unexpected character at line 1 column 1 of the JSON data

sasikumar1978k commented 1 year ago

image

sasikumar1978k commented 1 year ago

No response