Comments (5)
Hi Marijus,
I've written a new test to confirm that attributes passed to the widget are kept and rendered correctly, and they are indeed being rendered. Please see the test in address/tests/forms.py
if you'd like to check.
I wonder if perhaps when you say it doesn't work you are actually saying that your widget is still the same size after specifying size=150
, as opposed to the attributes are not being rendered? If that's the case, then the answer is because you're not specifying CSS sizes correctly. If you want to set the width of the widget via CSS directly on the widget class you will need to supply something like:
AddressWidget(attrs={"style": "width: 150px"})
Please note that while it's acceptable in Django to specify styles directly on the widget, I would not really recommend doing it this way; personally I prefer to restrict my styling to the templates to maintain a strict separation of form/view logic and presentation. But, each to their own!
Hope that helps! And please let me know if this has resolved your issue by replying to this comment so I can close the issue.
Cheers,
Luke
from django-address.
Hey,
I've updated my code as you said but it seems to have no effect. Style attribute is not being rendered.
<input class="address" id="id_address" name="address" type="text" placeholder="Enter a location" autocomplete="off">
Here's what's being rendered.
from django-address.
Hi again Marijus,
Ah, I see your problem. The formfield_overrides
requires keys that are model fields, not form fields. You're passing in the form field version of AddressField
, instead of the one associated with the model. Please use address.models.AddressField
instead, that should fix the issue.
Cheers,
Luke
from django-address.
Hey Luke,
Changed it but it didn't help. Here's updated code:
from django.contrib import admin
from .models import Property
from address.models import AddressField
from address.forms import AddressWidget
class PropertyAdmin(admin.ModelAdmin):
formfield_overrides = {
AddressField: {'widget': AddressWidget(attrs={"style": "width: 150px"})}
}
admin.site.register(Property, PropertyAdmin)
However I tried creating modelform and it worked:
from address.forms import AddressField, AddressWidget
from django import forms
class AddressForm(forms.Form):
address = AddressField(widget=AddressWidget(attrs={"style": "width: 300px"}))
This works as it should.
from django-address.
I think perhaps there may be something else wrong with your code then, as the example site I've included in django-address shows that the wider width admin widget works as expected. Can you please take a look at the example site and check that the widget in the admin is wider?
from django-address.
Related Issues (20)
- Add end-to-end tests
- Use Docker for example site HOT 2
- Admin does not query google HOT 2
- default Autofield and django 3.2
- Update translation to Django 4 HOT 1
- Nonexistent parent node ('address', '004_auto_20220227_1259') HOT 16
- Include serializers for usage inside rest framework HOT 2
- Error installing version 0.2.7 due to incorrect metadata HOT 1
- Python3.9 integration HOT 2
- Address save via admin saves the primary key into raw column, and additionally creates a bare new object HOT 3
- unique=True HOT 2
- Error when using together with Django autocomplete fields in admin HOT 3
- {{ form.media }} seems to render nothing in Django 4 HOT 2
- Address Form field only populates if full address is provided.
- Fill related models upon Address creation.
- Support for model serializer with django-rest-framework HOT 4
- Add documentation to readthedocs
- Prefer django_countries.fields.CountryField instead of implement address.models.Country
- AddressField on admin site
- Cant select address without `address_street_number`
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-address.