Comments (3)
Great! Thank you so much for the detailed explanation! I had it working using the recommended way so it is fine. Thank you! :)
from django-floppyforms.
Hi @javiermatos , sorry for the late reply on this (still figuring out the new Github notifications....)
So basically this is working "as expected". The way that Django works for this stuff when building a model form is:
- generate a set of fields for a model (using
fields_for_model
). So here this would be a call likeopts = cls.Meta default_fields = fields_for_models(models.Account, opts.fields, ..., opts.widgets, ....)
2 - set those up on the class (so at this point default_fields
will use the right widget, but it would not use the floppyforms.gis.PointField
but the default Django one)
3 - override these defaults with manually declared fields. for example you declared address_location
here, so that field overrides everything from fields_for_model
(including stuff built up on meta)
Now, if you want to use a custom widget, you have a couple options (haven't tested any of these but I believe variants of these ideas work)
- If you always want to use this
widget
for a model field, you can declare a default form field (with a default widget)
class CustomFormPointField(loppyforms.gis.PointField):
widget = CustomPointWidget
class CustomModelPointField(PointField): # this is a model field
field_class = CustomFormPointField
# use the above in your models, then form fields will automatically use the right kind of field
- If you more or less want to one-off this, you can declare
form_class
andwidgets
separately
class PointWidget(floppyforms.gis.PointWidget, floppyforms.gis.BaseOsmWidget):
pass
class AccountForm(forms.ModelForm):
class Meta:
model = models.Account
fields = '__all__'
widgets = {
'description': AdminTextareaWidget(),
'services': FilteredSelectMultiple(verbose_name='services', is_stacked=False),
'address_location': PointWidget(), # widget declared here...
}
field_classes = {
'address_location': floppyforms.gis.PointField # custom form field declared here
}
- ( VERY HACKY, PLEASE USE AT YOUR OWN RISK ) If you just want all model
PointFields
to do the right thing, you could edit the defaultwidget
class in yoursettings.py
or something:
class PointWidget(floppyforms.gis.PointWidget, floppyforms.gis.BaseOsmWidget):
pass
from django.db.contrib.gis.db.models.fields import PointField as DjangoPointField
DjangoPointField.widget = PointWidget
Hope this helps
from django-floppyforms.
Glad to hear that you were able to get things working 😄
from django-floppyforms.
Related Issues (20)
- How to use bootstrap style to `datalist`?!
- gis warning when I don't want to use gis HOT 5
- TypeError: get_context() got an unexpected keyword argument 'renderer' on Django 1.11.3 HOT 27
- VariableDoesNotExist: Failed lookup for key [help_text] in u'iban' HOT 1
- Custom radioselect required attrs Widget or rendered? HOT 1
- Endless Loop with django-debug-toolbar HOT 2
- the image_thumbnail.html example causes an error when image exist HOT 3
- Django 2.1 update causing for error, renderer() HOT 4
- Widgets not rendering extra attrs HOT 2
- Removed ORGException causes issues when using GeoDjango after 2.0 HOT 1
- Prepare 1.8.0 release
- Implement Jazzband guidelines for project django-floppyforms HOT 4
- [1.8.0 release blocker] Django templates breaking change? HOT 1
- Django 3 'six' incompatability HOT 2
- Is this project dead? HOT 7
- geodjango floppyform issue
- set extent of map using map_options HOT 3
- How to filter widget input datalist with user name
- Drop support for Python 3.6
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-floppyforms.