Ejemplo n.º 1
0
def add_sorted_one2many_relation(model_one,
                                 model_many,
                                 field_name_on_model_one=None,
                                 related_name_on_model_many=None):
    field_name = field_name_on_model_one or model_many._meta.model_name + '_set'
    related_name = related_name_on_model_many or model_one._meta.model_name
    field = SortedOneToManyField(model_many, related_name=related_name)
    field.contribute_to_class(model_one, field_name)
Ejemplo n.º 2
0
def add_sorted_one2many_relation(model_one,
                                 model_many,
                                 field_name_on_model_one=None,
                                 related_name_on_model_many=None):
    field_name = field_name_on_model_one or model_many._meta.model_name + '_set'
    related_name = related_name_on_model_many or model_one._meta.model_name
    field = SortedOneToManyField(model_many, related_name=related_name)
    field.contribute_to_class(model_one, field_name)
Ejemplo n.º 3
0
class Category(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField(Item, sorted=True, blank=True)

    class Meta:
        verbose_name_plural = "categories"

    def __str__(self):
        return self.name
Ejemplo n.º 4
0
class CategorySelf(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField('self',
                                 sorted=True,
                                 related_name='category',
                                 blank=True)

    class Meta:
        verbose_name_plural = "self categories"

    def __str__(self):
        return self.name
Ejemplo n.º 5
0
class CategoryStringRef(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField('ItemStringRef', sorted=True, related_name='category', blank=True)
Ejemplo n.º 6
0
class Category(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField(Item, sorted=True, blank=True)
Ejemplo n.º 7
0
    items = SortedOneToManyField('self', sorted=True, related_name='category', blank=True)


class ItemStringRef(models.Model):
    name = models.CharField(max_length=50)


class CategoryStringRef(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField('ItemStringRef', sorted=True, related_name='category', blank=True)


class ItemFixed(models.Model):
    name = models.CharField(max_length=50)


class CategoryFixed(models.Model):
    name = models.CharField(max_length=50)

inject_extra_field_to_model(CategoryFixed, 'items',
    SortedOneToManyField(ItemFixed, sorted=True, related_name='category', blank=True))


from .app2.models import M1, M2

inject_extra_field_to_model(M1, 'items',
    SortedOneToManyField(M2, sorted=True, related_name='category', blank=True))



Ejemplo n.º 8
0

class CategorySelf(models.Model):
    name = models.CharField(max_length=50)
    items = SortedOneToManyField('self',
                                 sorted=True,
                                 related_name='category',
                                 blank=True)

    class Meta:
        verbose_name_plural = "self categories"

    def __str__(self):
        return self.name


class CategoryFixed(models.Model):
    name = models.CharField(max_length=50)

    class Meta:
        verbose_name_plural = "fixed categories"


inject_extra_field_to_model(
    CategoryFixed, 'items', SortedOneToManyField(Item, sorted=True,
                                                 blank=True))

from django.contrib.auth.models import User
inject_extra_field_to_model(User, 'items',
                            SortedOneToManyField(Item, related_name='owner'))