Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Add support for GenericRelations#319

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mblayman merged 7 commits intodjango-json-api:developfromInvGate:feature/fix_get_related_resource_type_for_generic_relations
Feb 23, 2017
Merged

Add support for GenericRelations#319

mblayman merged 7 commits intodjango-json-api:developfromInvGate:feature/fix_get_related_resource_type_for_generic_relations
Feb 23, 2017

Conversation

santiavenda2
Copy link
Contributor

@santiavenda2santiavenda2 commentedFeb 1, 2017
edited
Loading

Fixed#224

Also, we fixed

ConftestImportFailure: (local('/home/santiago/develop/invgate-django-rest-framework-json-api/example/tests/conftest.py'), (<type 'exceptions.ImportError'>, ImportError('No module named faker',), <traceback object at 0x7f64f3d8c5a8>))

Fake-factory has been deprecated, changing its name toFaker

@santiavenda2santiavenda2 changed the titleChange fake-factory (deprecated) requirement to FakerAdd support for GenericRelationsFeb 1, 2017
@@ -58,3 +58,11 @@ class Meta:
body = factory.LazyAttribute(lambda x: faker.text())
author = factory.SubFactory(AuthorFactory)


class EntryTaggedItemFactory(factory.django.DjangoModelFactory):
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Could you call thisTaggedItemFactory instead ofEntryTaggedItemFactory? That seems more in line with the other factory naming conventions here.

@@ -3,6 +3,9 @@

from django.db import models
from django.utils.encoding import python_2_unicode_compatible
from django.contrib.contenttypes.models import ContentType
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

After reviewing this package's code, imports are usually alphabetically sorted. Could you move thesecontrib imports about thedb import?

@@ -30,11 +30,14 @@
if django.VERSION >= (1, 9):
from django.db.models.fields.related_descriptors import ManyToManyDescriptor, ReverseManyToOneDescriptor
ReverseManyRelatedObjectsDescriptor = type(None)
from django.contrib.contenttypes.fields import ReverseGenericManyToOneDescriptor
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This method of having two mirrored imports that set one to the None type is something I found confusing. After digging through the Django contenttypes source, I see that what is happening is trying to deal with a rename of the descriptor from 1.8 to 1.9. Unfortunately, this method leads to extra branches in an already large if/elif section.

How about using an import alias instead?

ifdjango.VERSION>= (1,9):# ... snip unmodified lines ...fromdjango.contrib.contenttypes.fieldsimportReverseGenericManyToOneDescriptorelse:fromdjango.contrib.contenttypes.fieldsimportReverseGenericRelatedObjectsDescriptorasReverseGenericManyToOneDescriptor

I believe this would clean up the code, be more efficient, and capture the fact that the descriptor was renamed. It seems this pattern was already followed for the first two imports that follow theelse.

Copy link
ContributorAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Done!

@@ -2,6 +2,6 @@
pytest>=2.9.0,<3.0
pytest-django
pytest-factoryboy
fake-factory
Faker
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

Thanks for picking up this package name change. This change has bit me on a few projects already.

@mblayman
Copy link
Collaborator

Thanks@santiavenda2 for the contribution! Making this work forGenericRelations is a feature that I'm sure many users will value considering the popularity of thecontenttypes system.

This feels like a feature worth documenting. Would you be able to do some of that? At the very least, I think starting a v2.X entry with a bullet point aboutGenericRelations should happen.

I'd be happy to merge after some minor modifications occur. 👍

@codecov-io
Copy link

codecov-io commentedFeb 23, 2017
edited
Loading

Codecov Report

Merging#319 intodevelop willincrease coverage by0.06%.
The diff coverage is89.58%.

@@             Coverage Diff             @@##           develop     #319      +/-   ##===========================================+ Coverage    91.58%   91.64%   +0.06%===========================================  Files           49       50       +1       Lines         2318     2359      +41     ===========================================+ Hits          2123     2162      +39- Misses         195      197       +2
Impacted FilesCoverage Δ
example/tests/integration/test_meta.py100% <ø> (ø)
.../tests/integration/test_non_paginated_responses.py100% <ø> (ø)
example/tests/integration/test_pagination.py100% <ø> (ø)
example/migrations/0002_taggeditem.py100% <100%> (ø)
example/serializers.py100% <100%> (ø)
example/factories/init.py97.67% <100%> (+0.3%)
example/tests/conftest.py100% <100%> (ø)
rest_framework_json_api/utils.py89.75% <60%> (-1.39%)
example/models.py94.82% <91.66%> (-0.83%)
... and1 more

Continue to review full report at Codecov.

Legend -Click here to learn more
Δ = absolute <relative> (impact),ø = not affected,? = missing data
Powered byCodecov. Last updatea19f445...f9bfcc9. Read thecomment docs.

@mblayman
Copy link
Collaborator

Nice work. Thanks,@santiavenda2!

santiavenda2 reacted with thumbs up emoji

@mblaymanmblayman merged commitfbe49a1 intodjango-json-api:developFeb 23, 2017
amw added a commit to amw/django-rest-framework-json-api that referenced this pull requestMay 7, 2017
PRdjango-json-api#319 brought support for generic relations. Unfortunately apps thatdon't add contenttypes to it's INSTALLED_APPS would crash and burn:```RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.```Also using `type(something) is object()` comparison as a saferalternative to `type(something) is type(None)`. If `something` happenedto be `None` we would enter a branch that was never supposed to run.
amw added a commit to amw/django-rest-framework-json-api that referenced this pull requestMay 7, 2017
PRdjango-json-api#319 brought support for generic relations. Unfortunately apps thatdon't add contenttypes to it's INSTALLED_APPS would crash and burn:```RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.```Also using `type(something) is object()` comparison as a saferalternative to `type(something) is type(None)`. If `something` happenedto be `None` we would enter a branch that was never supposed to run.
mblayman pushed a commit that referenced this pull requestMay 7, 2017
PR#319 brought support for generic relations. Unfortunately apps thatdon't add contenttypes to it's INSTALLED_APPS would crash and burn:```RuntimeError: Model class django.contrib.contenttypes.models.ContentType doesn't declare an explicit app_label and isn't in an application in INSTALLED_APPS.```Also using `type(something) is object()` comparison as a saferalternative to `type(something) is type(None)`. If `something` happenedto be `None` we would enter a branch that was never supposed to run.
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@mblaymanmblaymanmblayman left review comments

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@santiavenda2@mblayman@codecov-io

[8]ページ先頭

©2009-2025 Movatter.jp