TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'builtins': 'app.templatetags.extratags' # <<<<<<<<<<<<<<<
},
},
]
def get_lenta_elem(request):
items = Product.objects.all()
return {'items': items }
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
# custom context processor
'путь_к_файлу.навание_метода' # <<<<<<<<<<<<<
],
},
},
]
<input type="radio" name="choice" value="choice1">
<input type="radio" name="choice" value="choice2">
<input type="radio" name="choice" value="choice3">
choice = request.POST['choice']
print(choice)
>>> choice1
choice = request.POST.get('choice', None)
if choice:
делать ваш код
else:
вы не выбрали батон
class SupplyAdmin(admin.ModelAdmin):
available_fields = ('name', 'field1', 'field2')
hidden_fields = ('field3',)
def get_form(self, request, obj, **kwargs):
if request.user.username == 'example@example.com':
self.fields = self.available_fields + self.hidden_fields
else:
self.fields = self.available_fields
return super(SupplyAdmin, self).get_form(request, obj, **kwargs)
class ItemAttributeValue(models.Model):
att1 = .....
att2 = .....
item = models.ForeignKey(ItemAttribute, related_name='attribute')
characteristics = ItemAttribute.objects.get(category=3)
{% for i in characteristics %}
{{ i.name}}
...
{{ i.attribute.att1}}
...
{% endfor %}
class Phones(models.Model):
phone = models.CharField(max_length=50)
store = models.ForeignKey(Store, related_name='phone_number')
store = Store.objects.get(pk=1)
phone_num = store.phone_number.phone
{% if stores %}
<div class="footer-col-2">
<div class="col-name">Наши магазины</div>
<ul class='stores'>
{% for store in stores %}
<li>
<span>{{ store.name }} - {{ store.address }}</span>
<ul>
<li>{{ store.phone_number.name }}: {{ store.phone_number.phone }}</li>
</ul>
</li>
{% endfor %}
</ul>
</div>
{% endif %}
User.profile = property(lambda u: UserProfile.objects.get_or_create(user=u)[0])
if request.POST:
form = UserProfileForm(request.POST, request.FILES, instance=request.user.profile)
if form.is_valid():
form.save()