Skip to content

Some updates #8

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 our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions examples/simple/books/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
"""
Books app.
"""

default_app_config = 'books.apps.Config'
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
"""
Create test book data.
"""

from __future__ import unicode_literals

from django.core.management.base import BaseCommand, CommandError

import factories
Expand Down
1 change: 1 addition & 0 deletions examples/simple/books/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from .book import *
from .order import *
from .order_line import *
from .payment import *
from .profile import *
from .publisher import *
from .tag import *
7 changes: 2 additions & 5 deletions examples/simple/books/models/author.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,12 @@

from rest_framework_tricks.models.fields import NestedProxyField

from six import python_2_unicode_compatible

__all__ = (
'Author',
'AuthorProxy',
)


@python_2_unicode_compatible
class Author(models.Model):
"""Author."""

Expand Down Expand Up @@ -73,7 +70,7 @@ class Author(models.Model):
},
)

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["id"]
Expand Down Expand Up @@ -106,7 +103,7 @@ class AuthorProxy(Author):
'business_contact_information',
)

class Meta(object):
class Meta:
"""Meta options."""

proxy = True
12 changes: 3 additions & 9 deletions examples/simple/books/models/book.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,8 @@
"""

from django.db import models

from rest_framework_tricks.models.fields import NestedProxyField

from six import python_2_unicode_compatible

from ..constants import (
BOOK_PUBLISHING_STATUS_CHOICES,
BOOK_PUBLISHING_STATUS_DEFAULT,
Expand All @@ -20,7 +17,6 @@
)


@python_2_unicode_compatible
class Book(models.Model):
"""Book."""

Expand Down Expand Up @@ -59,7 +55,7 @@ class Book(models.Model):
'state',
)

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["isbn"]
Expand All @@ -71,7 +67,7 @@ def __str__(self):
class BookProxy(Book):
"""Book proxy model for to be used in testing."""

class Meta(object):
class Meta:
"""Meta options."""

proxy = True
Expand All @@ -80,9 +76,7 @@ class Meta(object):
class BookProxy2(Book):
"""Book proxy model for to be used in testing."""

class Meta(object):
class Meta:
"""Meta options."""

proxy = True


9 changes: 3 additions & 6 deletions examples/simple/books/models/order.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,13 @@

from django.conf import settings
from django.db import models
from django.utils.translation import ugettext

from six import python_2_unicode_compatible
from django.utils.translation import gettext

__all__ = (
'Order',
)


@python_2_unicode_compatible
class Order(models.Model):
"""Order."""

Expand All @@ -23,10 +20,10 @@ class Order(models.Model):
created = models.DateField(auto_now_add=True)
updated = models.DateField(auto_now=True)

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["-created"]

def __str__(self):
return ugettext('Order')
return gettext('Order')
8 changes: 2 additions & 6 deletions examples/simple/books/models/order_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,12 @@
"""

from django.db import models
from django.utils.translation import ugettext

from six import python_2_unicode_compatible

__all__ = (
'OrderLine',
)


@python_2_unicode_compatible
class OrderLine(models.Model):
"""Order line."""

Expand All @@ -22,10 +18,10 @@ class OrderLine(models.Model):
on_delete=models.CASCADE
)

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["order__created"]

def __str__(self):
return ugettext('{}').format(self.book.isbn)
return self.book.isbn
89 changes: 89 additions & 0 deletions examples/simple/books/models/payment.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
"""
Author model.
"""

from django.db import models

from rest_framework_tricks.models.fields import NestedProxyField

__all__ = (
'Payment',
"PaymentProxy",
)


class Payment(models.Model):
"""Payment."""

buyer_salutation = models.CharField(max_length=10)
buyer_name = models.CharField(max_length=200)
buyer_email = models.EmailField()
buyer_headshot = models.ImageField(upload_to='authors', null=True, blank=True)
buyer_birth_date = models.DateField(null=True, blank=True)
buyer_biography = models.TextField(null=True, blank=True)
buyer_phone_number = models.CharField(max_length=200, null=True, blank=True)
buyer_website = models.URLField(null=True, blank=True)

company_name = models.CharField(max_length=200, null=True, blank=True)
company_phone_number = models.CharField(max_length=200,
null=True,
blank=True)
company_email = models.EmailField(null=True, blank=True)
company_website = models.URLField(null=True, blank=True)

# This does not cause a model change
contact_information = NestedProxyField(
{
'buyer': (
('email', "buyer_email"),
('phone_number', "buyer_phone_number"),
('website', "buyer_website"),
)
},
{
'company': (
("name", "company_name"),
("email", 'company_email',),
("phone_number", 'company_phone_number',),
("website", 'company_website',),
)
},
)

class Meta:
"""Meta options."""

ordering = ["id"]

def __str__(self):
return self.name


class PaymentProxy(Payment):
"""Payment proxy model for to be used in testing."""

# This does not cause a model change
buyer = NestedProxyField(
'email',
'phone_number',
'website',
)

# This does not cause a model change
company = NestedProxyField(
("name", "company_name"),
("email", 'company_email',),
("phone_number", 'company_phone_number',),
("website", 'company_website',),
)

# This does not cause a model change
contact_information = NestedProxyField(
'buyer',
'company',
)

class Meta:
"""Meta options."""

proxy = True
8 changes: 2 additions & 6 deletions examples/simple/books/models/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
"""

from django.db import models

from rest_framework_tricks.models.fields import NestedProxyField

from six import python_2_unicode_compatible

__all__ = (
'Profile',
)


@python_2_unicode_compatible
class Profile(models.Model):
"""Profile."""

Expand Down Expand Up @@ -120,10 +116,10 @@ class Profile(models.Model):
# }
# }

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["id"]

def __str__(self):
return self.name
return self.email
6 changes: 1 addition & 5 deletions examples/simple/books/models/publisher.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,13 @@
"""

from django.db import models

from rest_framework_tricks.models.fields import NestedProxyField

from six import python_2_unicode_compatible

__all__ = (
'Publisher',
)


@python_2_unicode_compatible
class Publisher(models.Model):
"""Publisher."""

Expand All @@ -34,7 +30,7 @@ class Publisher(models.Model):
as_object=True
)

class Meta(object):
class Meta:
"""Meta options."""

ordering = ["id"]
Expand Down
4 changes: 2 additions & 2 deletions examples/simple/books/models/tag.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""

from django.db import models
from django.utils.translation import ugettext_lazy as _
from django.utils.translation import gettext_lazy as _

__all__ = (
'Tag',
Expand All @@ -15,7 +15,7 @@ class Tag(models.Model):

title = models.CharField(max_length=255, unique=True)

class Meta(object):
class Meta:
"""Meta options."""

verbose_name = _("Tag")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
# -*- coding: utf-8 -*-
"""
Temporary copy of the ``rest_framework_extensions.routers`` of the
``drf_extensions`` package. To be removed once the latter one is updated
to work with Django 2.0.
"""
from distutils.version import LooseVersion
from django.core.exceptions import ImproperlyConfigured

from nine.versions import DJANGO_GTE_1_10
from django.urls import NoReverseMatch

from rest_framework.routers import (
DefaultRouter,
Expand All @@ -25,11 +22,6 @@
)
from rest_framework_extensions.compat_drf import add_trailing_slash_if_needed

if DJANGO_GTE_1_10:
from django.urls import NoReverseMatch
else:
from django.core.urlresolvers import NoReverseMatch


class ExtendedActionLinkRouterMixin(object):
routes = [
Expand Down
Loading