def test_user_foreign_key_supports_migration(): """Tests serializing UserForeignKey in a simple migration. Since `UserForeignKey` is a ForeignKey migrations pass `to=` explicitly and we have to pop it in our __init__. """ fields = { 'charfield': UserForeignKey(), } migration = type(str('Migration'), (migrations.Migration,), { 'operations': [ migrations.CreateModel( name='MyModel', fields=tuple(fields.items()), bases=(models.Model,) ), ], }) writer = MigrationWriter(migration) output = writer.as_string() # Just make sure it runs and that things look alright. result = safe_exec(output, globals_=globals()) assert 'Migration' in result
class ThemeLock(ModelBase): theme = models.OneToOneField('addons.Persona') reviewer = UserForeignKey() expiry = models.DateTimeField() class Meta: db_table = 'theme_locks'
class ThemeLock(ModelBase): id = PositiveAutoField(primary_key=True) theme = models.OneToOneField('addons.Persona') reviewer = UserForeignKey() expiry = models.DateTimeField() class Meta: db_table = 'theme_locks'
def test_user_foreign_key_field_deconstruct(): field = UserForeignKey() name, path, args, kwargs = field.deconstruct() new_field_instance = UserForeignKey() assert kwargs['to'] == new_field_instance.to