question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

django-smart-select with django-material

See original GitHub issue

Hi

I had a look at issue #170 and have the same problem. I tried the workaround that was suggested, but unfortunately it does not work on the admin side. Everything works perfectly when django-material is disabled. I know the bug is not on your side, but it would be great if smart-selects would be able to work with django-material. Any help would be appreciated

Here is my model, the referenced foreignkey is in a different app and like I said smart-selects works without django-material enabled.

class Stock(models.Model):
	StockNumber = models.CharField(max_length=20, blank=True)
	MMCode = models.ForeignKey('mead.VehicleMM', related_name='vehicle')
	Year = ChainedForeignKey('mead.VehicleValue', chained_field="MMCode", chained_model_field="MMCode", show_all=False, auto_choose=True, sort=True)
	EngineNumber = models.CharField(max_length=50, verbose_name='Engine Number')
	VINNumber = models.CharField(max_length=50, verbose_name='VIN Number')
	RegistrationNumber = models.CharField(max_length=50, verbose_name='Registration Number')
	Colour = models.CharField(max_length=50)
	Mileage = models.IntegerField()
	FuelType = models.CharField(max_length=2, choices=FUEL_CHOICES, verbose_name='Fuel Type')
	NonFactoryAccessories = models.TextField(blank=True, verbose_name='Non Factory Accessories')
	PurchasePrice = models.DecimalField(max_digits=20, decimal_places=2)
	PaymentRemittanceNumber = models.CharField(max_length=100, blank=True, verbose_name='Payment Remittance Number')
	From = models.CharField(max_length=100, verbose_name='Vehicle Bought From')
	RetailValue = models.DecimalField(max_digits=20, decimal_places=2, null=True)
	ProfitMargin = models.DecimalField(max_digits=20, decimal_places=2, null=True)
	PurchaseDate = models.DateField()
	StandInValue = models.DecimalField(max_digits=20, decimal_places=2, null=True)
	NumberOfStockDays = models.IntegerField(null=True, verbose_name='Number of days in stock')
	SpareKeys = models.BooleanField(default=False)
	TrackingInstalled = models.BooleanField(default=False)
	SpareWheel = models.BooleanField(default=False)
	Jack = models.BooleanField(default=False)
	Tools = models.BooleanField(default=False)
	ServiceBooks = models.CharField(max_length=2, choices=SERVICE_CHOICES)
	Natis = models.FileField(upload_to='natis')
	LicenseRenewalDate = models.DateField()
	ServiceIntervals = models.CharField(max_length=100)
	NextServiceDueDate = models.DateField()
	NextServiceDueMileage = models.IntegerField()
	Status = models.CharField(max_length=2, choices=STATUS_CHOICES)

admin.py

class StockAdminForm(forms.ModelForm):
	class Meta:
		model = Stock
		widgets = {'Year': YearWidget(attrs={'to_app_name': 'stock',
											'to_model_name': 'Stock',
											'chained_field': 'MMCode',
											'chained_model_field': 'MMCode',
											'foreign_key_app_name': 'mead',
											'foreign_key_model_name': 'VehicleValue',
											'foreign_key_field_name': 'MMCode',
											'show_all': False,
											'auto_choose': True})}

@admin.register(Stock)
class StockAdmin(admin.ModelAdmin):
	list_display = ['StockNumber', 'Status']
	list_filter = ['Status',]
	search_fields = ['StockNumber',]
	raw_id_fields = ['MMCode',]
	form = StockAdminForm

widget.py as suggested workaround

from smart_selects.widgets import ChainedSelect

class YearWidget(ChainedSelect):
    def __init__(self, *args, attrs=None, **kwargs):
        self.attrs = attrs
        super(YearWidget, self).__init__(*args, **kwargs)
    
    def render(self, *args, **kwargs):
        super(YearWidget, self).render(*args, attrs=self.attrs, **kwargs)

The error I receive from shell

TypeError: init() missing 9 required positional arguments: ‘to_app_name’, ‘to_model_name’, ‘chained_field’, ‘chained_model_field’, ‘foreign_key_app_name’, ‘foreign_key_model_name’, ‘foreign_key_field_name’, ‘show_all’, and ‘auto_choose’

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5

github_iconTop GitHub Comments

1reaction
maldhureakshaycommented, Sep 17, 2018
1reaction
blagcommented, Oct 14, 2017

I don’t want to complicate the code in django-smart-selects any more than it already is (it’s brittle enough already), so I will not be fixing this.

The proper fix is to get django-material to properly render widgets as I noted in my comment on #170.

Sorry!

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-smart-select with django-material · Issue #232 - GitHub
Here is my model, the referenced foreignkey is in a different app and like I said smart-selects works without django-material enabled. class ...
Read more >
Django material with django smart select error - Stack Overflow
I'm using django smart select and django material in a project and getting 'NoneType' object is not subscriptable from the page ...
Read more >
django-smart-selects - Read the Docs
django -smart-selects documentation¶ · 1. Installation · 2. Settings · 3. Chained Selects · ChainedForeignKey options · 4. Chained ManyToMany Selects · Using...
Read more >
[Solved]-Django material with django smart select error-django
You have a bug in your code, in line #138 in smart_selects\widgets.py : File "C:\project\smart_selects\widgets.py" in render 138. "id": attrs['id'],.
Read more >
Material Forms - Viewflow
Django -Material offers the alternative approach to rendering forms in django. Strong Python/HTML code separation keeps you code DRY and free from underline ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found