Django - what is wrong with my If statement? - python

I inserted an if statement in my template - I only want the form to appear if the product category is "Champagne".
For some reason, the product does not appear for champagne products.
Here is the code
Models.py
CATEGORY=(
(1,'Rum'),
(2,'Gin'),
(3,'Whisky'),
(4,'Champagne'),
(5,'Others'),
)
class Product(models.Model):
name = models.CharField('Product Name', max_length=120, null=True)
category = models.IntegerField(choices=CATEGORY, default=0)
description = models.TextField(blank=True, null=True)
price = models.DecimalField(null=True, max_digits=6, decimal_places=3)
image_url= models.URLField('Image Web Address', blank=True)
product_url = models.URLField('Product Web Address', blank=True)
class Meta:
db_table='Product'
def __str__(self):
return str(self.name)
HTML
{% if product.category == 'Champagne' %}
<div class="d-flex flex-column mt-4">
<a class="btn btn-outline-secondary btn-sm" href="{% url 'ElderFlowerReview' product.id %}">Tasting Notes</a>
</div>
{% endif %}
Forms.py
class DrinkForm(ModelForm):
class Meta:
model = Product
fields = ('name','category', 'description')
labels ={
'name': '',
'category': '',
'description': '',
}
widgets = {
'name': forms.TextInput(attrs={'class':'form-control', 'placeholder':'Enter name'}),
'category': forms.Select(attrs={'class':'form-control', 'placeholder':'Enter category'}),
'description':forms.TextInput(attrs={'class':'form-control', 'placeholder':'Enter description'}),
}

You have to use 4 insted of "Champagne"
4 is value and "Champagne" is label
HTML
{% if product.category == 4 %}
<div class="d-flex flex-column mt-4">
<a class="btn btn-outline-secondary btn-sm" href="{% url 'ElderFlowerReview' product.id %}">Tasting Notes</a>
</div>
{% endif %}

Related

django prefetch_related() attribute error

How to properly user prefetch_related with ManyToMany relation
my model:
class Subject(models.Model):
subject_name = models.CharField(max_length=150)
subject_code = models.CharField(max_length=50)
year = models.ForeignKey(YearLevel, null=True, on_delete=models.SET_NULL)
units = models.CharField(max_length=10)
def __str__(self):
return self.subject_name + ' ' + '(' + self.subject_code + ')'
class Student(models.Model):
student = models.ForeignKey(settings.AUTH_USER_MODEL, limit_choices_to= Q(is_student=True), on_delete= models.CASCADE)
enrolled_subject = models.ManyToManyField(Subject)
my view:
def home(request):
verses = VerseOfTheDay.objects.all()
news = Announcement.objects.all()
student_grade_form = AddStudentGradeForm()
students = Student.objects.all().prefetch_related('subject_set')
context = {
"verse": verses,
'news': news,
'form': student_grade_form,
'students': students,
}
return render(request, 'sample.html', context)
my html:
{% for student in students %}
<p>
<a class="btn btn-primary" data-bs-toggle="collapse" href="#collapse{{forloop.counter}}" role="button" aria-expanded="false" aria-controls="collapse{{forloop.counter}}">
{{student.student}}
</a>
</p>
<div class="collapse" id="collapse{{forloop.counter}}">
<div class="card card-body">
{% for subject in student.subject_set.all %}
{{subject.subject}}
{% endfor %}
</div>
</div>
{% endfor %}
I am getting an error:
AttributeError at /
Cannot find 'subject_set' on Student object, 'subject_set' is an invalid parameter to prefetch_related()
Change this line
students = Student.objects.all().prefetch_related('subject_set')
to
students = Student.objects.all().prefetch_related('enrolled_subject')

Django RadioSelect Widget as Bootstrap Buttons?

I have a Django reviewing and photo sharing application.
When a user submits a new Review instance, they can indicate the 'Method of Consumption' using Select widget, which by default will show choices as a dropdown. This is a very bland look.
I want to use a custom Widget which will render the choices as buttons--not radio buttons, but bootstrap buttons Bootstrap5 Radio Toggle Buttons. This is far more visually appealing.
How do I render the widget such that for each choice, there is a button with value equal to the choice (Flower, Extract, Edible) as shown in the screenshot?
models.py
class Review(models.Model):
title = models.CharField(max_length=35)
content = models.TextField(max_length=500)
strain = models.ForeignKey(
Strain,
on_delete=models.CASCADE,
related_name="user_review"
)
user = models.ForeignKey(
settings.AUTH_USER_MODEL,
on_delete=models.PROTECT,
related_name="user_reviews",
default=1
)
photo = models.ImageField(
upload_to=upload_location,
blank=True,
null=True,
height_field="height_field",
width_field="width_field",
)
height_field = models.IntegerField(default=0, null=True)
width_field = models.IntegerField(default=0, null=True)
FLOWER = 'Flower'
EXTRACT = 'Extract'
EDIBLE = 'Edible'
METHOD_CHOICES = (
(FLOWER, 'Flower'),
(EXTRACT, 'Extract'),
(EDIBLE, 'Edible'),
)
method = models.CharField(
max_length=20,
choices=METHOD_CHOICES,
default='Flower',
blank=False
)
RATING_CHOICES = (
(1, '1'),
(2, '2'),
(3, '3'),
(4, '4'),
(5, '5'),
)
rating = models.IntegerField(choices=RATING_CHOICES, default=5)
timestamp = models.DateTimeField(auto_now=False, auto_now_add=True)
updated = models.DateTimeField(auto_now=True, auto_now_add=False)
users_like = models.ManyToManyField(
settings.AUTH_USER_MODEL,
related_name="reviews_liked",
blank=True
)
class Meta:
ordering = ["-timestamp", "-updated"]
def get_absolute_url(self):
return reverse("reviews:review_detail", kwargs={"id": self.id})
def __str__(self):
return self.title
forms.py
class ReviewForm(forms.ModelForm):
photo = forms.ImageField(
required=True,
)
FLOWER = 'Flower'
EXTRACT = 'Extract'
EDIBLE = 'Edible'
METHOD_CHOICES = (
(FLOWER, 'Flower'),
(EXTRACT, 'Extract'),
(EDIBLE, 'Edible'),
)
rating = forms.IntegerField(widget=Stars)
method = forms.ChoiceField(choices=METHOD_CHOICES, widget=MethodSelectWidget)
class Meta:
model = Review
fields = [
"rating",
"title",
"method",
"content",
"photo",
]
labels = {
'title': '',
'content': '',
'method': '',
}
help_texts = {
'method': 'Choose method of consumption'
}
widgets = {
'title': forms.TextInput(attrs={'placeholder': 'Title'}),
'content': forms.Textarea(attrs={'placeholder': 'Description'}),
}
def save(self):
instance = super(ReviewForm, self).save(commit=False)
instance.slug = slugify(instance.title)
instance.save()
return instance
widgets.py
class MethodSelectWidget(forms.Widget):
template_name = 'partials/reviews/widgets/method_select_widget.html'
def get_context(self, name, value, attrs=None):
return {'widget': {
'name': name,
'value': value,
}}
def render(self, name, value, attrs=None, renderer=None):
context = self.get_context(name, value, attrs)
template = loader.get_template(self.template_name).render(context)
return mark_safe(template)
method_select_widget.html
<h2>Form</h2>
<div class="btn-group btn-group-toggle" data-toggle="buttons">
<label class="btn btn-outline-success active">
<input type="radio" name="options" id="option1" autocomplete="off" checked>{{ widget.value }}
</label>
</div>
review_form.html
{% extends "base.html" %}
{% block head_title %}{{ strain.name }} Review | {{ block.super }}{% endblock head_title %}
{% load crispy_forms_tags %}
{% block content %}
<div class="container mt-5">
<div class="h-100 row justify-content-center align-items-center">
<div class="col-sm-6">
<h2 style="font-weight: 600;">Review {{ strain }}</h2>
<hr/>
<form method="POST" action="" enctype="multipart/form-data" class="form">
{% csrf_token %}
{{ form|crispy }}
<button type=submit style="background-color:#6eb257; color: white; font-weight: 600; font-size: 1.2rem; letter-spacing: 1px;"
class="mx-auto mt-3 mb-3 btn btn-block shadow">
Submit
</button>
</form>
</div>
</div>
</div>
{% endblock %}

Store multiple inputs values of form in single json to store in model field. - Django

I am working on a project which is online printing ordering service.
Here on the order page I am getting different attributes of product in radio button list in the form, and all the attributes I want to store in a single json in database.
models.py
class Product(models.Model):
prod_ID = models.AutoField("Product ID", primary_key=True)
prod_Name = models.CharField("Product Name", max_length=30, null=False)
prod_Desc = models.CharField("Product Description", max_length=2000, null=False)
prod_Price = models.IntegerField("Product Price/Piece", default=0.00)
prod_img = models.ImageField("Product Image", null=True)
def __str__(self):
return "{}-->{}".format(self.prod_ID,
self.prod_Name)
# this is the order table , there is a "attribute_field" I wantto store the attributes in this field
# as JSON.
class Order(models.Model):
order_id = models.AutoField("Order ID", primary_key=True)
user_id = models.ForeignKey(User, on_delete=models.CASCADE, null=False, verbose_name="Customer ID")
prod_id = models.ForeignKey(Product, on_delete=models.CASCADE, null=False, verbose_name="Product ID")
quantity = models.ImageField('Product Quantity', max_length=10, default=500)
attribute_value = models.CharField("Item Details JSON", max_length=2000, null=False)
order_date = models.DateField("Order Date", auto_now_add=True, null=False)
order_job_title = models.CharField("Name of Company/Business", max_length=100, null=False)
order_desc = models.CharField("Details for Product", max_length=1000, null=False)
product_img = models.ImageField("Template Image", null=False)
address = models.CharField("Customer Address ", max_length=100, null=False)
state = models.CharField("Customer State", max_length=30, null=False)
city = models.CharField("Customer City", max_length=30, null=False)
postal_code = models.IntegerField("Area Pin Code", null=False)
order_price = models.DecimalField(max_digits=8, decimal_places=2, default=0000.00)
class Size(models.Model):
size_id = models.AutoField("Size ID", primary_key=True, auto_created=True)
prod_size = models.CharField("Product Size", max_length=20, null=False)
def __str__(self):
return "{size_id}-->{prod_size}".format(size_id=self.size_id,
prod_size=self.prod_size)
class Color(models.Model):
color_id = models.AutoField("Color ID", primary_key=True, auto_created=True)
prod_color = models.CharField("Product Color", max_length=50, null=False)
def __str__(self):
return "{color_id}-->{prod_color}".format(color_id=self.color_id,
prod_color=self.prod_color)
class PaperChoice(models.Model):
paper_id = models.AutoField("Paper Choice ID", primary_key=True, auto_created=True)
paper_choices_name = models.CharField("Paper Choices", max_length=50, null=False)
def __str__(self):
return "{}-->{}".format(self.paper_id,
self.paper_choices_name)
class SizeProductMapping(models.Model):
size_p_map_id = models.AutoField("Size & Product Map ID", primary_key=True, auto_created=True)
size_id = models.ForeignKey(Size, null=False, on_delete=models.CASCADE, verbose_name="Size ID")
prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
class ColorProductMapping(models.Model):
color_p_map_id = models.AutoField("Color & Product Map ID", primary_key=True, auto_created=True)
color_id = models.ForeignKey(Color, null=False, on_delete=models.CASCADE, verbose_name="Color ID")
prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
class PaperChoiceProductMapping(models.Model):
paper_p_map_id = models.AutoField("Paper Choices & Product Map ID", primary_key=True, auto_created=True)
paper_id = models.ForeignKey(PaperChoice, null=False, on_delete=models.CASCADE, verbose_name="Paper ID")
prod_id = models.ForeignKey(Product, null=False, on_delete=models.CASCADE, verbose_name="Product Id")
this is my views.py and it is incomplete , I want to store the forms data in the model using this
view.
views.py
#here in thi view method I am only getting data from models but not getting template data to store in the the model,
# I know I haven't taken inputs from the form here
# I haven't done because I don't know what logic I should use here.
def order(request, id):
products = Product.objects.all()
sizesList = []
ColorsList = []
PaperChoiceProductsList = []
try:
sizesMap = SizeProductMapping.objects.filter(prod_id=id)
sizesList = [data.size_id.prod_size for data in sizesMap]
except AttributeError:
pass
try:
colorMap = ColorProductMapping.objects.filter(prod_id=id)
ColorsList = [data.color_id.prod_color for data in colorMap]
except AttributeError:
pass
try:
PaperChoiceProductMap = PaperChoiceProductMapping.objects.filter(prod_id=id)
PaperChoiceProductsList = [data.paper_id.paper_choices_name for data in PaperChoiceProductMap]
except AttributeError:
pass
context = {'products': products,
'sizesList': sizesList,
"ColorsList": ColorsList,
"PaperChoiceProductsList": PaperChoiceProductsList,
}
return render(request, 'user/order.html', context)
order.html
{% extends 'user/layout/userMaster.html' %}
{% block title %}Order{% endblock %}
{% block css %}
form
{
position:relative;
}
.tasksInput
{
margin-right:150px;
}
label
{
vertical-align: top;
}
{% endblock %}
{% block header %}
{% endblock %}
{% block main %}
<div class="container">
<div>
<div class="row rounded mx-auto d-block d-flex justify-content-center">
<button class="btn btn-secondary my-2 mr-1">Custom</button>
<button class="btn btn-secondary my-2 ml-1">Package</button>
</div>
<div class="row">
<div class="col-4">
<div class="card border border-secondary">
<div class="card body mx-2 mt-4 mb-2">
{% for product in products %}
<a id="{{ product.prod_ID }}" class="card-header" style="font-size:5vw;color:black;"
href="{% url 'user-order' product.prod_ID %}">
<h5 class="h5">{{ product.prod_ID }}. {{ product.prod_Name }}</h5></a>
<div class="dropdown-divider"></div>
{% endfor %}
</div>
</div>
</div>
<div class="col-8">
<form>
<div class="card mx-2 my-2 border border-secondary">
<div class="my-2">
<!-- The data I want to store in JSON starts from here -->
{% if sizesList %}
<div class="form-group">
<div class="form-group row mx-2">
<label for="sizeList"
class="form-control-label font-weight-bold card-header col-4 ml-4"
style="background-color:#e3e4e6"><h5>Sizes : </h5></label>
<div id="sizeList">
{% for s in sizesList %}
<input id="{{s}}" class="mx-2 my-auto" type="radio" name="size">
<label for="{{s}}">{{s}}</label><br>
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% if ColorsList %}
<div class="form-group">
<div class="form-group row mx-2">
<label for="ColorsList"
class="form-control-label font-weight-bold card-header col-4 ml-4"
style="background-color:#e3e4e6"><h5>Colors : </h5></label>
<div id="ColorsList">
{% for c in ColorsList %}
<input id="{{c}}" class="mx-2 my-auto" type="radio" name="Color">
<label for="{{c}}">{{c}}</label><br>
{% endfor %}
</div>
</div>
</div>
{% endif %}
{% if PaperChoiceProductsList %}
<div class="form-group">
<div class="form-group row mx-2">
<label for="ColorsList"
class="form-control-label font-weight-bold card-header col-4 ml-4"
style="background-color:#e3e4e6"><h5>Paper Choice : </h5></label>
<div id="PaperChoiceProductsList">
{% for pc in PaperChoiceProductsList %}
<input id="{{pc}}" class="mx-2 my-auto" type="radio" name="PaperChoice">
<label for="{{pc}}">{{pc}}</label><br>
{% endfor %}
</div>
</div>
</div>
{% endif %}
<!-- The Data I want to store in the JSON ends here -->
</div>
</div>
</div>
</form>
</div>
</div>
<div class="row rounded mx-auto d-block d-flex justify-content-center">
<button class="btn btn-success my-2">Place Order</button>
</div>
</div>
</div>
{% endblock %}
As mentioned in above template comment I want to store that data in single JSON.
Can you please help me to create a view for it.
urls.py
path('order/<int:id>', views.order, name="user-order"),
I used jason dump method to store value in single json object and then passed it to the field and it is working for me.
views.py
import json
def order(request, id):
products = Product.objects.all()
sizesList = []
ColorsList = []
PaperChoiceProductsList = []
value = {}
try:
sizesMap = SizeProductMapping.objects.filter(prod_id=id)
sizesList = [data.size_id.prod_size for data in sizesMap]
except AttributeError:
pass
try:
colorMap = ColorProductMapping.objects.filter(prod_id=id)
ColorsList = [data.color_id.prod_color for data in colorMap]
except AttributeError:
pass
try:
PaperChoiceProductMap = PaperChoiceProductMapping.objects.filter(prod_id=id)
PaperChoiceProductsList = [data.paper_id.paper_choices_name for data in PaperChoiceProductMap]
except AttributeError:
pass
if request.method == 'POST':
if request.method == 'POST':
customer_id = request.user
product = Product.objects.get(prod_ID=id)
product_id = product
try:
quantity = request.POST['quantity']
print(quantity)
except MultiValueDictKeyError:
pass
try:
size = request.POST['size']
value.update(size=size)
except MultiValueDictKeyError:
pass
try:
Colour = request.POST['Color']
value.update(Colour=Colour)
except MultiValueDictKeyError:
pass
try:
Paper_Choice = request.POST['PaperChoice']
value.update(Paper_Choice=Paper_Choice)
except MultiValueDictKeyError:
pass
attribute_value = json.dumps(value)
order_store = Order(user_id=customer_id, prod_id=product_id, quantity=quantity, attribute_value=attribute_value,
order_job_title=Job_title, order_desc=Order_Detail, address=User_Address, state=State,
city=City, postal_code=Postal_Code, product_img=TemplateValue)
order_store.save()
context = {'products': products,
'sizesList': sizesList,
"AqutousCoatingProductList": AqutousCoatingProductList,
"ColorsList": ColorsList,
"PaperChoiceProductsList": PaperChoiceProductsList,
}
return render(request, 'user/order.html', context)

Get Absolute Url keeps directing to one particular id

Good day, I have a Django project where I want to display an order list and detail. All seems to work perfectly but the link only links to one particular id ( for instance id 66). I have tried deleting the particular order id from the admin panel, thinking maybe the URL would just reset, but I get the URL id incremented, now it's no longer id 66 but 67. Pls how can I fix this? here are my codes:
models.py
class Order(models.Model):
user = models.ForeignKey(User, null=True, on_delete=models.CASCADE)
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
email = models.EmailField()
address = models.CharField(max_length=250)
phone_number = models.CharField(max_length=20)
city = models.CharField(max_length=100)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
paid = models.BooleanField(default=False)
braintree_id = models.CharField(max_length=150, blank=True)
coupon = models.ForeignKey(Coupon, related_name='orders', null=True, blank=True, on_delete=models.SET_NULL)
discount = models.IntegerField(default=0, validators=[
MinValueValidator(0),
MaxValueValidator(100)
])
class Meta:
ordering = ('-created',)
def __str__(self):
return self.first_name
def get_absolute_url(self):
return reverse('orders:orderdetail', args=[self.id])
views.py
def order_list(request):
orders = Order.objects.all()
current_user = request.user
success = Order.objects.filter(user=current_user.id).filter(paid=True)
fail = Order.objects.filter(user=current_user.id).filter(paid=False)
return render(request, 'orders/order/order_list.html', {
'success': success,
'fail': fail,
'current_user': current_user,
'orders':orders,
})
def order_detail(request, order_id):
order = get_object_or_404(Order, id=order_id)
return render(request, 'orders/order/order_detail.html', {'order': order})
urls.py
from django.urls import path
from . import views
app_name = 'orders'
urlpatterns = [
path('create/', views.order_create, name='order_create'),
path('admin/order/<int:order_id>/', views.admin_order_detail, name='admin_order_detail'),
path('admin/order/<int:order_id>/pdf/', views.admin_order_pdf, name='admin_order_pdf'),
path('addtocart/<int:id>', views.addtocart, name='addtocart'),
path('myorder/', views.order_list, name='orderlist'),
path('myorder/detail/<int:order_id>/', views.order_detail, name='orderdetail'),
]
html
{% for order in orders %}
<a href="{{ order.get_absolute_url }}" style="position: absolute; top: 5px; right: 5px;">
View Details
</a>
{% endfor %}
full html
<div class="col-md-9">
{% for od in success %}
<div class="card mb-3" style="max-width: 540px;">
<div class="row no-gutters">
<div class="col-md-3">
<img alt="product img" class="card-img" src="...">
</div>
<div class="col-md-9">
<div class="card-body" style="position: relative;">
<h5 class="card-title">Product {{ od.id }}</h5>
{% for order in orders %}
<a href="{{ order.get_absolute_url }}" style="position: absolute; top: 5px; right: 5px;">
View Details
</a>
{% endfor %}
<p class="card-text">
<mark style="color: whitesmoke; background-color: brown;border-radius: 3px;font-weight: bold;">{{transaction}}</mark>
</p>
<p class="card-text"><small class="text-muted">Delivered at
{{od.reference_id}}</small></p>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
The URL I get is like this /orders/myorder/detail/66/
I'm gonna add pictures to make it less abstract
Thanks.
Just like #EricMartin said, it was the context of the order
I realized I had {% for od in success %} and {% for order in orders %}
I guess they're not on good terms with each other and since orders is in success, I removed the {% for order in orders %} loop and all seems peaceful again :)

how do I add css to a specific field in a Django ModelForm

I have a model called Member, which contains a date field.
while trying to style the page, I realized I needed a few css classes on the field. I am having issues doing so.
Here is my forms.py AddMember class:
class AddMember(ModelForm):
class Meta:
model = Member
exclude = ['id', 'member_id', 'CurrentRank', 'Lat', 'Lng']
widgets = {
'date_joined': forms.TextInput(attrs={'class': 'form-control form-control-inline input-medium date-picker'})
}
help_texts = {
'first_name': 'The First Name of the new recruit',
'middle_name': 'The Middle Name or Initial of the new recruit',
'last_name': 'The Last Name of the new recruit',
'home_phone': 'for US, us xxx-xxx-xxxx for international use country code + city code + number',
'cell_phone': 'Optional',
'fax_number': 'Optional',
'street1': 'House number and Street',
'street2': 'c/o or organization',
'City': 'City',
'State': 'State',
'Zip': 'Zip Code',
'Country': 'Select Country from drop down',
'Eye_Color': 'Eye Color',
'Hair_Color': 'Hair Color',
'Height': 'In Inches',
'date_joined': 'When the member joined first time'
}
it is joined to the Model Member:
class Member(models.Model):
id = models.AutoField(primary_key=True)
member_id = models.CharField(unique=True, max_length=30)
first_name = models.CharField(max_length=30)
middle_name = models.CharField(max_length=30)
last_name = models.CharField(max_length=30)
email = models.CharField(max_length=50)
Eye_Color = models.CharField(null=True, max_length=30)
Hair_Color = models.CharField(null=True, max_length=30)
Height = models.IntegerField(blank=True, null=True)
home_phone = PhoneNumberField(blank=True)
cell_number = PhoneNumberField(blank=True)
fax_number = PhoneNumberField(blank=True)
street1 = models.CharField(max_length=255, blank=True)
street2 = models.CharField(max_length=255, blank=True)
City = models.CharField(max_length=100, blank=True)
State = models.CharField(max_length=2, blank=True)
Zip = models.CharField(max_length=5, blank=True)
Country = CountryField()
Lat = models.FloatField(blank=True, null=True)
Lng = models.FloatField(blank=True, null=True)
date_joined = models.DateField()
invite_reason = models.CharField(max_length=64)
User = models.ForeignKey(User, blank=True, null=True)
from there, I put it in the template:
<form role="form" action="/members/add/" method="post" class="form-horizontal">
{% csrf_token %}
<div class="form-body">
{% for field in form %}
<div class="form-group form-md-line-input">
<label class="col-md-2 control-label" for="{{ field.name }}">{{ field.label }}</label>
<div class="col-md-10">
{{field|addcss:"form-control"}}
<div class="form-control-focus">
</div>
{% if field.help_text %}
<span class="help-block">{{ field.help_text|safe }}</span>
{% endif %}
</div>
</div>
{% endfor %}
</div>
<div class="form-actions">
<div class="row">
<div class="col-md-offset-2 col-md-10">
<button type="button" class="btn default">Cancel</button>
<button type="Submit" class="btn blue">Submit</button>
</div>
</div>
</div>
</form>
I need the field 'date_joined' to have the added css classes so the front end can actuate the dropdown selection of the date. when I fire off the page, it returns normal like all of the other fields.
What am I missing?
Thanks
UPDATE 1:
sometime ago, to add a default css tag to an object, I was to create a template tag:
#register.filter(name='addcss')
def addcss(field, css):
return field.as_widget(attrs={"class": css})
I am using it in the template.
apparently it's overriding the field. How do I set this default in forms.py and override for the one field?
Thanks.
You may take a look at django-widget-tweaks

Categories

Resources