Пример #1
0
from django.core.management.color import no_style
from django.contrib.contenttypes import generic
from django.db.models.sql.query import setup_join_cache

from deleting.models import ControlledDeletion


class MyClass(ControlledDeletion):
    class Meta:
        app_label = 'temporary_test'

    title = models.CharField(max_length=255, blank=True)
    content = models.TextField(max_length=2000, blank=True)


setup_join_cache(MyClass)


def create_tables():
    cursor = connection.cursor()
    style = no_style()
    tables = connection.introspection.table_names()
    seen_models = connection.introspection.installed_models(tables)

    sql, references = connection.creation.sql_create_model(
        MyClass, style, seen_models)

    pending_references = {}
    for refto, refs in references.items():
        pending_references.setdefault(refto, []).extend(refs)
        if refto in seen_models:
Пример #2
0
    date_foundation = models.DateField(blank=True, null=True)

    def __unicode__(self):
        return self.name


class Purchase(models.Model):
    class Meta:
        app_label = 'reversion_relations'

    date = models.DateTimeField(blank=True, default=datetime.datetime.now)
    supplier = FossilForeignKey(Supplier, null=True, blank=True)
    user = models.ForeignKey(User, null=True, blank=True)


setup_join_cache(Supplier)
setup_join_cache(Purchase)


def create_tables():
    cursor = connection.cursor()
    style = no_style()
    tables = connection.introspection.table_names()
    seen_models = connection.introspection.installed_models(tables)

    sql, references = connection.creation.sql_create_model(
        Supplier, style, seen_models)
    new_sql, new_ref = connection.creation.sql_create_model(
        Purchase, style, seen_models)
    sql.extend(new_sql)
    references.update(new_ref)
Пример #3
0
class FlatPageTranslation(Translation):
    class Meta:
        app_label = 'temporary_test'

    title = models.CharField(max_length=255, blank=True)
    content = models.TextField(max_length=2000, blank=True)

FlatPage.translations = generic.GenericRelation(FlatPageTranslation)
FlatPage.translations.contribute_to_class(FlatPage, 'translations')

class FlatPageRelative(models.Model):
    page = models.ForeignKey(FlatPage, related_name='page_relatives')
    information = models.TextField(blank=True)

setup_join_cache(FlatPageTranslation)
setup_join_cache(FlatPageRelative)

def create_tables():
    cursor = connection.cursor()
    style = no_style()
    tables = connection.introspection.table_names()
    seen_models = connection.introspection.installed_models(tables)

    sql, references = connection.creation.sql_create_model(FlatPageTranslation, style, seen_models)
    new_sql, new_ref = connection.creation.sql_create_model(FlatPageRelative, style, seen_models)
    sql.extend(new_sql); references.update(new_ref)

    pending_references = {}
    for refto, refs in references.items():
        pending_references.setdefault(refto, []).extend(refs)
Пример #4
0
    starred = models.BooleanField(default=False, blank=True)
    points = models.IntegerField(default=0, blank=True)
    date_foundation = models.DateField(blank=True, null=True)

    def __unicode__(self):
        return self.name

class Purchase(models.Model):
    class Meta:
        app_label = 'reversion_relations'

    date = models.DateTimeField(blank=True, default=datetime.datetime.now)
    supplier = FossilForeignKey(Supplier, null=True, blank=True)
    user = models.ForeignKey(User, null=True, blank=True)

setup_join_cache(Supplier)
setup_join_cache(Purchase)

def create_tables():
    cursor = connection.cursor()
    style = no_style()
    tables = connection.introspection.table_names()
    seen_models = connection.introspection.installed_models(tables)

    sql, references = connection.creation.sql_create_model(Supplier, style, seen_models)
    new_sql, new_ref = connection.creation.sql_create_model(Purchase, style, seen_models)
    sql.extend(new_sql); references.update(new_ref)

    pending_references = {}
    for refto, refs in references.items():
        pending_references.setdefault(refto, []).extend(refs)
Пример #5
0
from django.core.management.color import no_style
from django.contrib.contenttypes import generic
from django.db.models.sql.query import setup_join_cache

from deleting.models import ControlledDeletion


class MyClass(ControlledDeletion):
    class Meta:
        app_label = "temporary_test"

    title = models.CharField(max_length=255, blank=True)
    content = models.TextField(max_length=2000, blank=True)


setup_join_cache(MyClass)


def create_tables():
    cursor = connection.cursor()
    style = no_style()
    tables = connection.introspection.table_names()
    seen_models = connection.introspection.installed_models(tables)

    sql, references = connection.creation.sql_create_model(MyClass, style, seen_models)

    pending_references = {}
    for refto, refs in references.items():
        pending_references.setdefault(refto, []).extend(refs)
        if refto in seen_models:
            sql.extend(connection.creation.sql_for_pending_references(refto, style, pending_references))