Giter Club home page Giter Club logo

django-any-urlfield's People

Contributors

glowka avatar kingel avatar olarcheveque avatar vdboor avatar vitaly4uk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

django-any-urlfield's Issues

Issue when running syncdb on fresh database with models registered

When I run syncdb on a fresh database it crashes complaining it can't find a relationship.

Looking at the stack trace it looks like its something to do with any url fields. If I remove my two calls to AnyUrlField.register_model() in my Models.py it seems to fix it.

My hunch is that syncdb does some validation before running and this is where its trying to inspect the relationships created when registering a model with AnyURLField?

Here is my stack trace:

Traceback (most recent call last): File "./manage.py", line 10, in <module> execute_from_command_line(sys.argv) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line utility.execute() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute self.fetch_command(subcommand).run_from_argv(self.argv) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv self.execute(*args, **options.__dict__) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/base.py", line 284, in execute self.validate() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/base.py", line 310, in validate num_errors = get_validation_errors(s, app) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/management/validation.py", line 34, in get_validation_errors for (app_name, error) in get_app_errors().items(): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/loading.py", line 196, in get_app_errors self._populate() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/loading.py", line 75, in _populate self.load_app(app_name, True) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/loading.py", line 99, in load_app models = import_module('%s.models' % app_name) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/debug_toolbar/models.py", line 63, in <module> patch_root_urlconf() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/debug_toolbar/models.py", line 51, in patch_root_urlconf reverse('djdt:render_panel') File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/urlresolvers.py", line 480, in reverse app_list = resolver.app_dict[ns] File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/urlresolvers.py", line 310, in app_dict self._populate() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/urlresolvers.py", line 262, in _populate for pattern in reversed(self.url_patterns): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/urlresolvers.py", line 346, in url_patterns patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/core/urlresolvers.py", line 341, in urlconf_module self._urlconf_module = import_module(self.urlconf_name) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/Users/matt/PROJECTS/client/2014/da2014/da/da/da/urls.py", line 9, in <module> admin.autodiscover() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/contrib/admin/__init__.py", line 29, in autodiscover import_module('%s.admin' % app) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/utils/importlib.py", line 40, in import_module __import__(name) File "/Users/matt/PROJECTS/client/2014/da2014/da/da/core/admin.py", line 1, in <module> from .forms import (ChildPageForm, NewsPageForm, BlogPageForm, HomePageForm, File "/Users/matt/PROJECTS/client/2014/da2014/da/da/core/forms.py", line 22, in <module> class HomePagePromotionForm(ModelForm): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/forms/models.py", line 282, in __new__ opts.help_texts, opts.error_messages) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/forms/models.py", line 201, in fields_for_model formfield = f.formfield(**kwargs) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/any_urlfield/models/fields.py", line 81, in formfield return super(AnyUrlField, self).formfield(**kwargs) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 705, in formfield return super(CharField, self).formfield(**defaults) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/fields/__init__.py", line 554, in formfield return form_class(**defaults) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/any_urlfield/forms/fields.py", line 44, in __init__ widget = self.widget(url_type_registry=url_type_registry) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/any_urlfield/forms/widgets.py", line 71, in __init__ if getattr(form_field, 'choices', None) and getattr(widget, 'choices', None): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/forms/models.py", line 1048, in __len__ return len(self.queryset) +\ File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/query.py", line 77, in __len__ self._fetch_all() File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/query.py", line 854, in _fetch_all self._result_cache = list(self.iterator()) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/query.py", line 220, in iterator for row in compiler.results_iter(): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 709, in results_iter for rows in self.execute_sql(MULTI): File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 782, in execute_sql cursor.execute(sql, params) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute return super(CursorDebugWrapper, self).execute(sql, params) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/Users/matt/.virtualenvs/da2014/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute return self.cursor.execute(sql, params) django.db.utils.ProgrammingError: relation "core_hubpage" does not exist LINE 1: ...core_hubpage"."level", "core_hubpage"."body" FROM "core_hubp...

[bug] Don't raise `ValueError: Model is already registered`.

Registering the same model from different apps raises:

ValueError: Model is already registered: '<class 'MyModel'>'

but this should not happen, because AnyUrlField could be used by different apps and each app should be allowed to register all the models that it needs, regardless of the models registered by other apps.

Possible solutions:

  1. Don't raise ValueError, just ignore the registration of a model already registered.

  2. When registering a model, check from which app the model is registered and raise a ValueError only if the model has been registered more than once from the same app.

[feature] Add possibility to filter model querysets.

It would be very useful to have the possibility to filter models, for example if you don't want that backend users set the url of an unpublished object.

It would be nice doing it by passing the manager, like in get_object_or_404:

AnyUrlField.register_model(Products.objects_published, widget=SimpleRawIdWidget(Products))

Thank you for this great field.

Raw ID Fields search

In the docs, it says that the widget should appear just as a regular raw ID field, but it's missing the essential search field. You can see it in the screenshot below, right next to a normal raw id field.

screen shot 2016-11-21 at 5 57 02 pm

Thoughts? Solution?

Lambda prevents models using this field from pickling

I'm trying to set up object caching for my Django project but the Any Urlfields I'm using are keeping the python serializer from pickling. It seems that this use of a lambda is causing it to throw this error:

 Can't pickle <type 'function'>: attribute lookup __builtin__.function failed

Is there a reason that you want to leave this callable?

Could the lambda be removed?

form_field = forms.ModelChoiceField(queryset=model._default_manager.all(), widget=widget)

Or if it needs to be callable, a partial function could work:

from functools import partial

def model_choice_field(model, widget):
    return forms.ModelChoiceField(queryset=model._default_manager.all(), widget=widget)
....
form_field = partial(model_choice_field, model, widget)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.