Giter VIP home page Giter VIP logo

django-generic-m2m's People

Contributors

coleifer avatar coordt avatar jayfk avatar jpic avatar marky1991 avatar n3storm avatar quiqueporta 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  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

django-generic-m2m's Issues

ValidationError raised in admin interface when used with django-autocomplete-light

We are guessing it is related to django-generic-m2m because the error says ValidationError: [u"AutocompleteMediaItems cannot validate ['37-1', '24-36', '24-35', '24-30', '24-31', '33-135', '24-29', '24-28', '24-27', '33-121', '33-120', '33-118', '33-113', '33-112', '33-111', '33-109', '33-105', '33-100', '33-99', '33-98', '33-97', '33-96', '33-95', '33-94', '33-93', '33-92', '33-89', '33-81', '33-73', '33-66', '33-55']"] but we aren't quite sure if it's related to the generic m2m yet.

More details here: yourlabs/django-autocomplete-light#128

Admin Interface

What do you think of a RelatedObjectsDescriptor widget for the admin, such as SelectMultiple?

Get all by type

relations have an all() method for getting all related objects..

>>> type(pizza.related.all())
<class 'genericm2m.models.GFKOptimizedQuerySet'>
>>> pizza.related.all().generic_objects()
[<Beverage: beer>]

..but there doesn't seem to be a way to get all of the objects of just a certain type, which is part of the reason for using generic keys in the first place.

ie, I want something like this:

>>> pizza.related.all_by_type(Beverage)
[<Beverage: beer>]

If I wrote this to match all, would you accept it as a pull request? Or am I just ignoring an obvious way of doing this.

Initial migration fails

When creating initial database tables I always get error:

django.db.utils.OperationalError: (1005, 'Can\'t create table whatever.#sql-78b5_cf7 (errno: 150 "Foreign key constraint is incorrectly formed")')

Then I do python manage.py migrate again and everything goes fine. Applications works fine.

I made django print the statement and this is what I get when error happens:

ALTER TABLE `genericm2m_relatedobject` ADD CONSTRAINT `generi_parent_type_id_49334ec02e973f24_fk_django_content_type_id` FOREIGN KEY (`parent_type_id`) REFERENCES `django_content_type` (`id`)

Don't know if I will get errors further in application heavy use or is something I can pass.

Also is a bit of an annoyance for automation scripts.

Reverse related descriptor

Currently we can do:

In [4]: Document.objects.get(pk=1).related.all()
Out[4]: [<RelatedObject: avatar_big.png related to test ("")>]

But this isn't implemented:

In [5]: TestModel.objects.get(name='test').related.all()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
/home/jpic/env/local/lib/python2.7/site-packages/django/core/management/commands/shell.pyc in <module>()
----> 1 TestModel.objects.get(name='test').related.all()

I was expecting something like:

In [5]: TestModel.objects.get(name='test').related.all()
Out[4]: [<RelatedObject: avatar_big.png related to test ("")>]

If you like the idea I'm willing to propose a POC. As mentioned in issue #2, we have a nice widget for the admin, but it doesn't go both ways ....

Older versions of Django

I am using Django 1.4.22 so migrations are not included in the framework. I see django-generic-m2m uses the migrations package though, so I cannot install it.

I was using it before with no problem. What can I do?

Unable to install package with pip: python setup.py egg_info failed

I have been spending hours on this and I just cannot get it to work. When trying to install with pipi install django-generic-m2m I just keep getting an exception raised by the convert_path method in utils.py from distutils. It says ValueError: path 'example/' cannot end with '/'.

This is the full stack trace:

  Using cached django-generic-m2m-0.3.0.tar.gz
    Complete output from command python setup.py egg_info:
    running egg_info
    creating pip-egg-info\django_generic_m2m.egg-info
    writing pip-egg-info\django_generic_m2m.egg-info\PKG-INFO
    writing top-level names to pip-egg-info\django_generic_m2m.egg-info\top_level.txt
    writing dependency_links to pip-egg-info\django_generic_m2m.egg-info\dependency_links.txt
    writing manifest file 'pip-egg-info\django_generic_m2m.egg-info\SOURCES.txt'
    warning: manifest_maker: standard file '-c' not found

    reading manifest file 'pip-egg-info\django_generic_m2m.egg-info\SOURCES.txt'
    reading manifest template 'MANIFEST.in'
    warning: no files found matching 'LICENSE.txt'
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "c:\users\pablo\appdata\local\temp\pip-build-dcl6j_\django-generic-m2m\setup.py", line 32, in <module>
        test_suite='runtests.runtests',
      File "c:\python27\lib\distutils\core.py", line 152, in setup
        dist.run_commands()
      File "c:\python27\lib\distutils\dist.py", line 953, in run_commands
        self.run_command(cmd)
      File "c:\python27\lib\distutils\dist.py", line 972, in run_command
        cmd_obj.run()
      File "c:\python27\lib\site-packages\setuptools\command\egg_info.py", line 279, in run
        self.find_sources()
      File "c:\python27\lib\site-packages\setuptools\command\egg_info.py", line 306, in find_sources
        mm.run()
      File "c:\python27\lib\site-packages\setuptools\command\egg_info.py", line 535, in run
        self.read_template()
      File "c:\python27\lib\site-packages\setuptools\command\sdist.py", line 113, in __read_template_hack
        orig.sdist.read_template(self)
      File "c:\python27\lib\distutils\command\sdist.py", line 315, in read_template
        self.filelist.process_template_line(line)
      File "c:\python27\lib\site-packages\setuptools\command\egg_info.py", line 334, in process_template_line
        (action, patterns, dir, dir_pattern) = self._parse_template_line(line)
      File "c:\python27\lib\distutils\filelist.py", line 105, in _parse_template_line
        dir_pattern = convert_path(words[1])
      File "c:\python27\lib\distutils\util.py", line 202, in convert_path
        raise ValueError, "path '%s' cannot end with '/'" % pathname
    ValueError: path 'example/' cannot end with '/'

    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in c:\users\pablo\appdata\local\temp\pip-build-dcl6j_\django-generic-m2m\

Duplicate connections

We have found rare instances of duplicated connections in the relatedobject table.

The scenario in which we are using generic M2M is to keep a list of attached Reference Values on an XML object. We iterate through the list and attach the Reference Value objects to the original XML object. In the rare cases where the duplication has occurred, the date created field of the table shows that they were created approximately 2 seconds apart from each other.

The error occurs when we attempt another processing run of the XML object. When we attempt the connection the "second" time, the get_or_create in the connection model fails to catch the MultipleObjectsReturned error.

We cannot reliably reproduce the problem. In our database we have approximately 700k connections and have only had about a dozen errors.

We are now trapping the errors and have considered adding a unique together on the related object table.

Sorry I don't have a reproducible scenario.

add translations

esp. when using generic-m2m with the admin-interface, translations would be helpful ... e.g.
parent_type = models.ForeignKey(ContentType, verbose_name=("Object-Type"), related_name="child%(class)s")

IMO, using transifex is currently the best solution.

Q: are multiple related fields permissible on one model?

Is there a way to put more than one RelatedObjectsDescriptor field on a model? Can I do something like this (in keeping with silly examples):

class Store(models.Model):
    foods = RelatedObjectsDescriptor()
    beverages = RelatedObjectsDescriptor()

where I'm able to query just the foods and beverages like so:

 store.foods.all()
 store.beverages.all()

My first attempt returned both foods and beverages from the queries above. I suppose a simple workaround could be to use alias (or some custom field on a custom related_model) like so:

store.foods.connect(pizza, alias='food')
store.beverages.connect(beer, alias='beverage')

store.foods.filter(alias='food')
store.beverages.filter(alias='beverage')

...or something in that direction, but I wonder if there's a more elegant, built-in, or best-practice way of doing this?

Thanks!

P.S. I just realized my example was poorly constructed because it seems as though I could just use a regular m2m in that case, but assume I want to be able to relate different models on each field – the necessity for gm2m is assumed.

Handle non-existent relation "genericm2m_relatedobject"

I have received the following error when applying the migrations for an app:

ProgrammingError: relation "genericm2m_relatedobject" does not exist

The problem appears to be that genericm2m is installed in the virtualenv
and gets imported from autocomplete_light, but its tables do not exist.

I think that genericm2m should handle the case where its table/relation
does not exist. This might happen in other cases, too.

genericm2m does not show up in the Traceback itself. This might be due to
the signal handling?!

The following content types are stale and need to be deleted:

    app | foofile
    …

Any objects related to these content types by a foreign key will also
be deleted. Are you sure you want to delete these content types?
If you're unsure, answer 'no'.

    Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "…/src/manage.py", line 37, in <module>
    execute_from_command_line(sys.argv)
  File "venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 399, in execute_from_command_line
    utility.execute()
  File "venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 392, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "venv/lib/python2.7/site-packages/django/core/management/base.py", line 242, in run_from_argv
    self.execute(*args, **options.__dict__)
  File "venv/lib/python2.7/site-packages/django/core/management/base.py", line 285, in execute
    output = self.handle(*args, **options)
  File "venv/lib/python2.7/site-packages/south/management/commands/migrate.py", line 111, in handle
    ignore_ghosts = ignore_ghosts,
  File "venv/lib/python2.7/site-packages/south/migration/__init__.py", line 220, in migrate_app
    success = migrator.migrate_many(target, workplan, database)
  File "venv/lib/python2.7/site-packages/south/migration/migrators.py", line 254, in migrate_many
    result = migrator.__class__.migrate_many(migrator, target, migrations, database)
  File "venv/lib/python2.7/site-packages/south/migration/migrators.py", line 335, in migrate_many
    interactive=self.interactive)
  File "venv/lib/python2.7/site-packages/south/db/generic.py", line 1030, in send_pending_create_signals
    interactive=interactive)
  File "venv/lib/python2.7/site-packages/south/db/generic.py", line 1076, in really_send_create_signal
    db=self.db_alias,
  File "venv/lib/python2.7/site-packages/django/dispatch/dispatcher.py", line 185, in send
    response = receiver(signal=self, sender=sender, **named)
  File "venv/lib/python2.7/site-packages/django/contrib/contenttypes/management.py", line 81, in update_contenttypes
    ct.delete()
  File "venv/lib/python2.7/site-packages/django/db/models/base.py", line 695, in delete
    collector.delete()
  File "venv/lib/python2.7/site-packages/django/db/models/deletion.py", line 260, in delete
    qs._raw_delete(using=self.using)
  File "venv/lib/python2.7/site-packages/django/db/models/query.py", line 476, in _raw_delete
    sql.DeleteQuery(self.model).delete_qs(self, using)
  File "venv/lib/python2.7/site-packages/django/db/models/sql/subqueries.py", line 85, in delete_qs
    self.get_compiler(using).execute_sql(None)
  File "venv/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 782, in execute_sql
    cursor.execute(sql, params)
  File "venv/lib/python2.7/site-packages/django/db/backends/util.py", line 69, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "venv/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
  File "venv/lib/python2.7/site-packages/django/db/utils.py", line 99, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "venv/lib/python2.7/site-packages/django/db/backends/util.py", line 53, in execute
    return self.cursor.execute(sql, params)
ProgrammingError: relation "genericm2m_relatedobject" does not exist
LINE 1: DELETE FROM "genericm2m_relatedobject" WHERE "genericm2m_rel...
                    ^

It appears to get triggered through the post_delete signal:

> venv/lib/python2.7/site-packages/django/db/models/deletion.py(282)delete()
    281                         signals.post_delete.send(
--> 282                             sender=model, instance=obj, using=self.using
    283                         )

ipdb> model
<class 'django.contrib.contenttypes.models.ContentType'>
ipdb> obj
<ContentType: foo file>

Django 1.6.2, django-generic-m2m==0.2.2

Deprecation warnings.

Running off Django master we get the following warning:

RemovedInDjango19Warning: django.contrib.contenttypes.generic is deprecated and will be removed
in Django 1.9. Its contents have been moved to the fields, forms, and admin submodules of
django.contrib.contenttypes.
from django.contrib.contenttypes.generic import GenericForeignKey

The imports will need updating. I'll have a look later. Any opinions?

help_text and verbose_name keyword arguments

Hi,

isn't it possible to use help_text and verbose_name argument in the RelatedObjectsDescriptor?

related = RelatedObjectsDescriptor(verbose_name=("Belongs to"), help_text=_("For instance: in the case of a course, you can create a link to the course description to allow one to retrieve this calendar entry for the course description"))

Thanks,

Alex

Release on Pypi

Last release uploaded on Pypi is one year old. django-generic-m2m has improved a lot since then !

It would be great if we could have a new release on Pypi.

Keep up the good work.

doctest in tests

very cool project! would you mind describing (in docstrings perhaps?) what is the goal/expected result of each test?

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.