Hello Django community :D
i am currently learning django and am working on a vehicle app
where i currently have this models.py
class Engine(models.Model):
objects = EngineManager()
manufacture = models.CharField(max_length=80)
name = models.CharField(max_length=80)
filter_to_use = models.ManyToManyField('Filter') #this is in another app
class Meta:
unique_together = (('manufacture', 'name'),)
def natural_key(self):
return (self.manufacture, self.name)
def __unicode__(self):
return self.__str__()
def __str__(self):
return self.manufacture+' - '+self.name
class Vehicle_Model(models.Model):
engine = models.ForeignKey(Engine, on_delete=models.CASCADE)
name = models.CharField(max_length=100)
year_from = models.IntegerField(blank=True, null=True)
year_to = models.IntegerField(blank=True, null=True)
serial_number_from = models.CharField(max_length=100, blank=True,
null=True)
serial_number_to = models.CharField(max_length=100, blank=True,
null=True)
picture = models.ImageField(upload_to=modell_picture_path,
default='machine_models/none.png')
........
and i am trying to create a form for Engine.filter_to_use that will open in
a modal
the form currently looks like this:
class AddEngineFilterAjaxForm(PopRequestMixin, CreateUpdateAjaxMixin,
forms.ModelForm):
class Meta:
model = Engine
fields = ('filter_to_use',)
widgets = {'filter_to_use': forms.SelectMultiple(),}
def __init__(self, *args, **kwargs):
super(AddEngineFilterAjaxForm, self).__init__(*args, **kwargs)
self.fields['filter_to_use'].widget.attrs['class'] = 'selectpicker
form-control'
self.fields['filter_to_use'].widget.attrs['data-live-search'] =
'true'
self.fields['filter_to_use'].widget.attrs['title'] = 'Which filter
fits in the engine?'
and i am struggling with the view and right now im pretty lost of all the
trial and error :P
but i want it to have pre-selected all filters that are bound to the engine
and i want to be able to save the form.
it does look right, but the behaviour is not what i wanted.
any tips on how to write a class based view for this?
thanks in advance!
--
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 [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CAPLZMbMipUkgqbZiM0jVCrrJk4V6%2Bwqimup5PY4%2BC6iiT18xwA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.