2

Good day i seem to be lost in how i want to implement something. so here is how it goes

ive got a carowner model

 class carowner(models.Model):
     .....
     carowner = models.CharField(primary_key=True)

and a cars model

class car(models.Model):
    ....
    carowner_id = models.ForeignKey(carowner)

it has a foreignkey cause each car can only have one carowner but a carowner can have many cars but i run into a situation where

ive got a modelform

class assigncarownertocar(forms.ModelForm):
    car= forms.ModelChoiceField(widget=MultipleSelect())
    class Meta:
        model=carowner
        fields = [# all fields that are needed ]

what i want to happen is when im creating a new carowner asigns him multiple cars in the same form from a queryset i provided when the modelform is initialized. so everything loads fine in the form. i see the list of cars but once i select one or more i get this

'Select a valid choice. 539421 is not one of the available choices.

what i am asking is should i add the modelmultiplechoicefield to the model that holds the foreign key? cause right now i have it attached to the carowner model. i dont see documentation stating that this is wrong

Blue
  • 195
  • 1
  • 4
  • 9

0 Answers0