def __init__(self, of=models.TextField, **kwargs): # The `of` argument is a bit tricky once we need compatibility # with South. # # South can't store a field, and the eval it performs doesn't # put enough things in the context to use South's internal # "get field" function (`BaseMigration.gf`). # # Therefore, we need to be able to accept a South triple of our # sub-field and hook into South to get the correct thing back. if isinstance(of, tuple) and SOUTH: from south.utils import ask_for_it_by_name as gf of = gf(of[0])(*of[1], **of[2]) # Arrays in PostgreSQL are arrays of a particular type. # Save the subtype in our field class. if isinstance(of, type): of = of() self.of = of # Set "null" to True. Arrays don't have nulls, but null=True # in the ORM amounts to nothing in SQL (whereas null=False # corresponds to `NOT NULL`) kwargs["null"] = True super(ArrayField, self).__init__(**kwargs)
def __init__(self, of=models.IntegerField, **kwargs): # The `of` argument is a bit tricky once we need compatibility # with South. # # South can't store a field, and the eval it performs doesn't # put enough things in the context to use South's internal # "get field" function (`BaseMigration.gf`). # # Therefore, we need to be able to accept a South triple of our # sub-field and hook into South to get the correct thing back. if isinstance(of, tuple) and south_installed: from south.utils import ask_for_it_by_name as gf of = gf(of[0])(*of[1], **of[2]) # Arrays in PostgreSQL are arrays of a particular type. # Save the subtype in our field class. self.of = of if isinstance(self.of, type): self.of = self.of() # Set "null" to True. Arrays don't have nulls, but null=True # in the ORM amounts to nothing in SQL (whereas null=False # corresponds to `NOT NULL`) kwargs['null'] = True # Now pass the rest of the work to the Field superclass. super(ArrayField, self).__init__(**kwargs)