def __init__(self, to, chained_field=None, chained_model_field=None, show_all=False, auto_choose=False, **kwargs):
     if isinstance(to, basestring):
         self.app_name, self.model_name = to.split('.')
     else:
         self.app_name = to._meta.app_label
         self.model_name = to._meta.object_name
     self.chain_field = chained_field
     self.model_field = chained_model_field
     self.show_all = show_all
     self.auto_choose = auto_choose
     ForeignKey.__init__(self, to, **kwargs)
Beispiel #2
0
    def __init__(self, to, address_field=None, **kwargs):

        if isinstance(to, six.string_types):
            self.app_name, self.model_name = to.split('.')
        else:
            self.app_name = to._meta.app_label
            self.model_name = to._meta.object_name

        self.address_field = address_field
        kwargs.setdefault('blank', True)
        kwargs.setdefault('null', True)

        ForeignKey.__init__(self, to, **kwargs)
    def __init__(self, to, chained_field=None, chained_model_field=None,
                 show_all=False, auto_choose=False, sort=True, view_name=None, **kwargs):
        """
        examples:

        class Continent(models.Model):
            name = models.CharField(max_length=255)

        class Country(models.Model):
            continent = models.ForeignKey(Continent)

        class Location(models.Model):
            continent = models.ForeignKey(Continent)
            country = ChainedForeignKey(
                Country,
                chained_field="continent",
                chained_model_field="continent",
                show_all=True,
                auto_choose=True,
                sort=True,
                # limit_choices_to={'name':'test'}
            )
        ``chained_field`` is the name of the ForeignKey field referenced by ChainedForeignKey of the same Model.
        in the examples, chained_field is the name of field continent in Model Location.

        ``chained_model_field`` is the name of the ForeignKey field referenced in the 'to' Model.
        in the examples, chained_model_field is the name of field continent in Model Country.

        ``show_all`` controls whether show other choices below the filtered choices, with separater '----------'.

        ``auto_choose`` controls whether auto select the choice when there is only one available choice.

        ``sort`` controls whether or not to sort results lexicographically or not.

        ``view_name`` controls which view to use, 'chained_filter' or 'chained_filter_all'.

        """
        if isinstance(to, six.string_types):
            self.to_app_name, self.to_model_name = to.split('.')
        else:
            self.to_app_name = to._meta.app_label
            self.to_model_name = to._meta.object_name
        self.chained_field = chained_field
        self.chained_model_field = chained_model_field
        self.show_all = show_all
        self.auto_choose = auto_choose
        self.sort = sort
        self.view_name = view_name
        ForeignKey.__init__(self, to, **kwargs)
 def __init__(self, to, chained_field=None, chained_model_field=None,
              show_all=False, auto_choose=False, view_name=None, exclude_self=None, **kwargs):
     if isinstance(to, basestring):
         self.app_name, self.model_name = to.split('.')
     else:
         self.app_name = to._meta.app_label
         self.model_name = to._meta.object_name
     self.chain_field = chained_field
     self.model_field = chained_model_field
     self.show_all = show_all
     self.auto_choose = auto_choose
     self.view_name = view_name
     ForeignKey.__init__(self, to, **kwargs)
     self.exclude_self = exclude_self
     #TODO: clean-up
     if exclude_self:
         self.exclude_self = exclude_self
Beispiel #5
0
 def __init__(self,
              to,
              chained_field=None,
              chained_model_field=None,
              show_all=False,
              auto_choose=False,
              **kwargs):
     if isinstance(to, basestring):
         self.app_name, self.model_name = to.split('.')
     else:
         self.app_name = to._meta.app_label
         self.model_name = to._meta.object_name
     self.chain_field = chained_field
     self.model_field = chained_model_field
     self.show_all = show_all
     self.auto_choose = auto_choose
     ForeignKey.__init__(self, to, **kwargs)
    def __init__(self, to, chained_field=None, chained_model_field=None,
                 show_all=False, auto_choose=False, view_name=None, **kwargs):
        """
        examples:

        class Continent(models.Model):
            name = models.CharField(max_length=255)

        class Country(models.Model):
            continent = models.ForeignKey(Continent)

        class Location(models.Model):
            continent = models.ForeignKey(Continent)
            country = ChainedForeignKey(
                Country,
                chained_field="continent",
                chained_model_field="continent",
                show_all=True,
                auto_choose=True,
                # limit_choices_to={'name':'test'}
            )
        ``chained_field`` is the name of the ForeignKey field referenced by ChainedForeignKey of the same Model.
        in the examples, chained_field is the name of field continent in Model Location.

        ``chained_model_field`` is the name of the ForeignKey field referenced in the 'to' Model.
        in the examples, chained_model_field is the name of field continent in Model Country.

        ``show_all`` controls whether show other choices below the filtered choices, with separater '----------'.

        ``auto_choose`` controls whether auto select the choice when there is only one available choice.

        ``view_name`` controls which view to use, 'chained_filter' or 'chained_filter_all'.

        """
        if isinstance(to, six.string_types):
            self.to_app_name, self.to_model_name = to.split('.')
        else:
            self.to_app_name = to._meta.app_label
            self.to_model_name = to._meta.object_name
        self.chained_field = chained_field
        self.chained_model_field = chained_model_field
        self.show_all = show_all
        self.auto_choose = auto_choose
        self.view_name = view_name
        ForeignKey.__init__(self, to, **kwargs)
Beispiel #7
0
 def __init__(self, to='fias.AddrObj', **kwargs):
     kwargs.setdefault('related_name', '+')
     ForeignKey.__init__(self, to, **kwargs)
Beispiel #8
0
 def __init__(self, to, group_field, **kwargs):
     self.group_field = group_field
     self._choices = True
     ForeignKey.__init__(self, to, **kwargs)
Beispiel #9
0
 def __init__(self, to='fias.AddrObj', on_delete=models.CASCADE, **kwargs):
     kwargs.setdefault('related_name', '+')
     ForeignKey.__init__(self, to, on_delete, **kwargs)
Beispiel #10
0
 def __init__(self, to='fias.AddrObj', **kwargs):
     ForeignKey.__init__(self, to, **kwargs)
Beispiel #11
0
 def __init__(self, to='fias.AddrObj', **kwargs):
     kwargs.setdefault('related_name', '+')
     ForeignKey.__init__(self, to, **kwargs)
 def __init__(self, translated_field, language, to, to_field=None, *args,
              **kwargs):
     self._related_pre_init(translated_field, language, *args, **kwargs)
     ForeignKey.__init__(self, to, to_field, **kwargs)
     self._related_post_init()
Beispiel #13
0
 def __init__(self, to, chained_field, chained_model_field, *args, **kwargs):
     self.app_name = to._meta.app_label
     self.model_name = to._meta.object_name
     self.chain_field = chained_field
     self.model_field = chained_model_field
     ForeignKey.__init__(self, to, *args, **kwargs)
Beispiel #14
0
 def __init__(self, to, to_field=None, rel_class=ManyToOneRel, **kwargs):
     ForeignKey.__init__(self, to, to_field=to_field, rel_class=rel_class, **kwargs)
     self.on_delete = DO_NOTHING
Beispiel #15
0
 def __init__(self, to='fias.AddrObj', **kwargs):
     ForeignKey.__init__(self, to, **kwargs)
 def __init__(self, to, group_field, **kwargs):
     self.group_field = group_field
     self._choices = True
     ForeignKey.__init__(self, to, **kwargs)
Beispiel #17
0
 def __init__(self, to='fias.AddrObj', **kwargs):
     kwargs.setdefault('related_name', '+')
     ForeignKey.__init__(self, to, **kwargs, on_delete=models.SET_NULL)