0

My goal is to be able to select a location and Input part numbers without seeing this quote field. I dont even completely understand what this select box is looking for. I have Quote objects saved and yet these are not coming up as selectable options. Not that I want them to, Im just saying. My thinking regarding the seelctable options is that this would be auto-populated? You can probably tell my confusion even in my explanation. Ultimately, I dont want to see a select box at all as Im not really interested in whatever this pointing to, but just for kicks would like to know what it is trying to point to.

quote/Models.py

class Quote(models.Model): 
    QUOTE_ENVIRONMENTS = (
        ('testing', 'Test'),
        ('production', 'Production')
    )
    SALES_SOURCE=((1, 'Marketplace'),
        (2, 'Webstore'),
        (3, 'Physical Store'),
        (4, 'Phone')
        )
    environment = models.CharField(max_length=20, choices=QUOTE_ENVIRONMENTS, default="testing") 
    sales_source = models.IntegerField(choices=SALES_SOURCE, null=True) 
    order_notes = models.TextField(blank=True)
    locations = models.ManyToManyField('products.ProductSelection')

products/models.py

class Product(models.Model):
    pass

class Warehouse(models.Model):
    pass

class ProductSelection(models.Model):
    location = models.ForeignKey('Warehouse', on_delete = models.CASCADE)
    product = models.ManyToManyField('Product') 

Admin.py

class ProductOrderForm(forms.ModelForm):
    locations = forms.ModelChoiceField(queryset= Warehouse.objects.all())
    part_number = forms.IntegerField()
    def clean_product_id(self):
        cd = self.cleaned_data
        logger.info(cd)
        value = cd['part_number']
        if value not in Products.objects.list_part_numbers():
            raise forms.ValidationError("Not a valid partnumber")
            
class ProductSelectionTabularInline(admin.TabularInline):
    form = ProductOrderForm
    model = Quote.locations.through



class QuoteAdmin(admin.ModelAdmin):
    
    list_display=['id', 'environment', 'order_notes','sales_source']
    list_editable = ['environment', 'sales_source', 'order_notes']
    inlines = [ProductSelectionTabularInline]
    exclude=['quote']

Error when using exclude attr.

ERRORS:
<class 'orders.admin.ProductSelectionTabularInline'>: (admin.E201) Cannot exclude the field 'quote', because it is the foreign key to the parent model 'orders.Quote'.

I dont want the left most box. Thanks for your help

enter image description here

enjoi4life411
  • 568
  • 5
  • 11

1 Answers1

0

I figure out that the field to the left is the ProductSelection instance. I confused myself by adding the other 2 form widgets. So this does not allow me to do what I want which is to edit the parts to the locations and add it to the form for creating a quote.

enjoi4life411
  • 568
  • 5
  • 11