Giter Site home page Giter Site logo

django-reverse-unique's People

Contributors

akaariai avatar charettes avatar holvianssi avatar

Stargazers

 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

django-reverse-unique's Issues

Is this a small error in the README file?

First of all, this project is a great idea. Thanks!

From https://github.com/akaariai/django-reverse-unique/blame/f0dd7c01ae8ed6193a7ee26b7f4e4195ae42dadd/README.rst#L59-L60

current_salary = models.ReverseUnique(
    "EmployeeSalary",
    filter=Q(valid_from__gte=datetime.now) &
           (Q(valid_until__isnull=True) | Q(valid_until__lte=datetime.now))
)

aren't the valid_from and valid_until filters swapped so we can actually an employee's current salary?

current_salary = models.ReverseUnique(
    "EmployeeSalary",
    filter=Q(valid_from__lte=datetime.now) &
           (Q(valid_until__isnull=True) | Q(valid_until__gte=datetime.now))
)

prefetch_related doesn't work

Should you be able to include a ReverseUnique field in prefetch_related? Something like Lang.objects.all().prefetch_related('articletranslation_set__article__active_translation'). Currently this raises an error:

  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 96, in __iter__
    self._fetch_all()
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 856, in _fetch_all
    self._prefetch_related_objects()
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 517, in _prefetch_related_objects
    prefetch_related_objects(self._result_cache, self._prefetch_related_lookups)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 1598, in prefetch_related_objects
    obj_list, additional_prl = prefetch_one_level(obj_list, prefetcher, attr)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 1697, in prefetch_one_level
    prefetcher.get_prefetch_queryset(instances)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/fields/related.py", line 277, in get_prefetch_queryset
    qs = self.get_queryset(instance=instances[0]).filter(**query)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 590, in filter
    return self._filter_or_exclude(False, *args, **kwargs)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/query.py", line 608, in _filter_or_exclude
    clone.query.add_q(Q(*args, **kwargs))
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1198, in add_q
    clause = self._add_q(where_part, used_aliases)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1232, in _add_q
    current_negated=current_negated)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1100, in build_filter
    allow_explicit_fk=True)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1351, in setup_joins
    names, opts, allow_many, allow_explicit_fk)
  File "/srv/python-environments/eadfe1e8e3d19d09/local/lib/python2.7/site-packages/django/db/models/sql/query.py", line 1274, in names_to_path
    "Choices are: %s" % (name, ", ".join(available)))
FieldError: Cannot resolve keyword '+' into field. Choices are: abstract, article, body, id, lang, title

Make this a proper Python package

I'd like to do three things:

  • Place this under different github account (so that changing the maintainer will be easy)
  • Create proper documentation (I haven't ever done this for any package, so pointers welcome)
  • Create a pypi package

CI-tests would be nice, too.

As said above I haven't done a package before, so if somebody has some experience of how to do the above mentioned things, I'm all ears.

Allow filters to be callable.

Passing callable arguments to queryset is deprecated as of Django 1.9.

Filters such as Q(lang=get_language) or Q(from_date__lte=date.today) are no longer valid.

We should allow the filters kwarg to be a callable,

def get_active_translation_filters():
    return Q(lang=get_language())

active_translation = ReverseUnique(
    'ArticleTranslation', filters=get_active_translation_filters
)

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.