class EditForm(forms.ModelForm):
category = forms.ModelChoiceField(
queryset=Category.objects.all(),
label='Categories',
widget=forms.Select()
)
class Meta:
model = Item
fields = ('category', 'mode', 'type', 'delivery' )
Category
из моделей.models.py
class Audit(models.Model):
"""
A common class for auditing the models' instances.
"""
created_by = models.ForeignKey(
User,
related_name='%(app_label)s_%(class)s_created_related',
verbose_name=_(u'Создал'),
on_delete=models.SET_NULL,
blank=True, null=True)
changed_by = models.ForeignKey(
User,
related_name='%(app_label)s_%(class)s_changed_related',
verbose_name=_(u'Изменил'),
on_delete=models.SET_NULL,
blank=True, null=True)
created = models.DateTimeField(
_(u'Дата создания'), auto_now_add=True)
changed = models.DateTimeField(
_(u'Дата изменения'), auto_now=True)
class Meta:
abstract = True
admin.py
class AuditAdmin(admin.ModelAdmin):
"""
Admin class for audit fields
"""
readonly_fields = (
'created_by',
'changed_by',
'created',
'changed')
fieldsets_preset = (
_(u'Прочее'), {
'fields': (
'created_by',
'created',
'changed_by',
'changed'
)
})
actions_on_top = True
def save_model(self, request, obj, form, change):
if not change:
obj.created_by = request.user
obj.changed_by = request.user
obj.save()
class property(object):
def __init__(self, fget):
self.fget = fget
def __get__(self, obj, type = None):
return self.fget(obj)
obj = Person()
# obj.full_name_2()
Person.__dict__['full_name_2'](obj)
# obj.full_name_1
Person.__dict__['full_name_1'].__get__(obj)
yum install policycoreutils-python
# semanage port -l | grep http_port
http_port_t tcp 80, 81, 443, 488, 8008, 8009, 8443, 9000
# semanage port -a -t http_port_t -p tcp 8082
entries__set
is_published=True
, когда сами же пишете, что нужны неопубликованные... class BookAdmin(admin.ModelAdmin):
list_display = ("pk", "get_title_or_nothing")
def get_form(self, request, obj=None, **kwargs):
if obj.type == "1":
self.exclude = ("title", )
form = super(BookAdmin, self).get_form(request, obj, **kwargs)
return form
class CarAdmin(admin.ModelAdmin):
list_display = ("pk", "model", "vin")
def get_form(self, request, obj=None, **kwargs):
if 'Red' not in obj.color:
self.exclude = ("field1", "field2")
form = super(CarAdmin, self).get_form(request, obj, **kwargs)
return form
# cat ~/.gitconfig
branch-name = "!git rev-parse --abbrev-ref HEAD"
publish = "!git push -u origin $(git branch-name)"
git config --global push.default current
sudo systemctl enable lighttpd
- добавляет сервис в автозапуск, то же самое, но disable - отключает автозапускsudo systemctl start lighttpd
sudo update-rc.d -f lighttpd remove
и sudo service lighttpd start/stop
относятся к "старой" системе запуска демонов - init