def class_prepared(self, cls): class_ptr_name = cls.__name__.lower() attrs = { class_ptr_name: ReverseDictField(related_name=self.name, key=self.key_field_name, value=self.value_field_name), self.key_field_name: self.key_field, self.value_field_name: self.value_field, } self.dict_model = create_intermediate_model(cls, self.name, attrs, meta={ 'unique_together': (class_ptr_name, self.value_field_name), })
def create_list_model(cls, name, value_field, index='index', value='value', db_table=None, field_cls=ReverseListField): class_ptr_name = cls.__name__.lower() attrs = { class_ptr_name: field_cls(get_model_ref(cls), related_name=name, index=index, value=value), index: models.PositiveIntegerField(), value: value_field, } meta = { 'unique_together': (class_ptr_name, index), } if db_table: meta['db_table'] = db_table return create_intermediate_model(cls, name, attrs, meta=meta)