[Django]Djangoが出力しているSQLを見る方法
- November 10th, 2009
from django.db import connection print connection.queries
このとき、「DEBUG = True」(settingsで設定)になっている必要がある。
Popularity: 3% [?]
Posts Tagged ‘ Python ’
from django.db import connection print connection.queries
このとき、「DEBUG = True」(settingsで設定)になっている必要がある。
Popularity: 3% [?]
settings.pyに以下を追加
DATABASE_OPTIONS = {
'init_command': 'SET storage_engine=INNODB',
}
Popularity: 2% [?]
class User
name = models.CharField(max_length=255)
class Position
name = models.CharField(max_length=255)
class UserPosition(models.Model):
user = models.ForeignKey(User)
poistion = models.ForeignKey(Position)
class Meta:
unique_together (('user', 'poistion'),)
Popularity: 2% [?]
class SkillInlineFormset(BaseInlineFormSet):
def __init__(self, *args, **kwargs):
super(SkillInlineFormset, self).__init__(*args, **kwargs)
self.can_delete = False
class SkillInline(admin.TabularInline):
formset = SkillInlineFormset
model = Skill
extra = 5
Popularity: 2% [?]
Admin画面でSelectを表示した場合、デフォルトで”———–”の値が入ってしまう。
それを消す方法。
すごい調べたのだが・・・結局、「default=1」という感じでdefault値指定をして
あげればいいようだ。
class Job(models.Model):
name = models.CharField(max_length=255)
class User(models.Model):
name = models.CharField(max_length=255)
job = models.ForeignKey(Job, default=1)
class UserAdmin(admin.ModelAdmin):
class Meta:
model = User
Popularity: 5% [?]
def create_table(self, model):
from django.db import connection, transaction, models
from django.core.management.color import no_style
cursor = connection.cursor()
sql, references = connection.creation.sql_create_model(model, no_style())
for statement in sql:
cursor.execute(statement)
Popularity: 2% [?]
Dynamic Kyewords Arguments
def test(arg1, arg2):
test(**{'argr2': 'abcd'})
print arg1, arg2
Popularity: 1% [?]