Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8361943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T11:49:14+00:00 2026-06-09T11:49:14+00:00

I’m learning how to program in python/django and I’ve challenged myself to build an

  • 0

I’m learning how to program in python/django and I’ve challenged myself to build an ecommerce site for a printing business. The general idea follows:

Once the customer chooses a product, he will have to select from a set of options(Size, Frame-Border Width, Material) in order to customize his product. Something worth mentioning is that each option has characteristics that distinguish it from the others. For example: Each size has a width and a height wich are attributes not required for a Material. Then he will upload an image (but I ain’t there yet) and the store will process his order.

Therefore, I’ve chosen to design the models.py as follow (simplified):

class Product(models.Model):
    title = models.CharField(max_length = 150)
    slug = models.SlugField(max_length = 150)
    base_price = models.DecimalField(max_digits = 12, decimal_places = 2, default=0.00)

    class Meta:
        verbose_name = ('Product')
        verbose_name_plural = ('Products')

    #Methods. There is a method for each option.
    def get_materials(self):
        materials = self.materials.all()
        return materials

#There is a model for each option. Each model has a ForeignKey to Product.
class Material(models.Model):
    product = models.ForeignKey(Product, verbose_name = "Product", related_name="materials")
    name = models.CharField(max_length = 150)
    code = models.SlugField(max_length=150)
    price_per_meter = models.DecimalField(max_digits = 12, decimal_places = 2, blank = True, default = 0.00)
    created_at = models.DateTimeField(auto_now_add = True)

    class Meta:
        ordering = ["-created_at"]
        verbose_name_plural = "Materials"

To simplify things I’m using DetailView. So in my catalogue.urls.py:

from django.conf.urls import patterns, include, url
from django.views.generic import DetailView
from catalogue.models import Product

urlpatterns = patterns('',
    url(r'^(?P<pk>\d+)/$', DetailView.as_view(
        model = Product,
        template_name = "detail.html"
        )),
)

So, here is the question finally:

How can I customize my DetailView so that in the UI each option displays as RadioSelect?

Similar questions have been posted, but they are more related to forms: i.e. how to display a ForeignKey as a RadioSelect in a form.

My current approach uses the following detail.html

{% extends "base.html" %}

{% block content %}

<h1>{{ product.title }}</h1>

<h2>Please select one of the following:</h2>
<p>{{ product.get_materials }}</p>
<p>{{ product.get_sizes }}</p>
<p>{{ product.get_border_width }}</p>
<p>{{ product.get_border_color }}</p>

{% endblock %}

That renders the following:
I added some random data to the db

Please select one of the following:

[<Material: Material 1>, <Material: Material 2>]

[<Size: Size 1>, <Size: Size 2>]

[<BorderWidth: Border 1>, <BorderWidth: Border 2>]

[<BorderColor: Color 1>, <BorderColor: Color 1>]

Any help/pin-pointing in the right direction will be appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T11:49:15+00:00Added an answer on June 9, 2026 at 11:49 am

    In short, a DetailView is for displaying data. Given that you’re asking the user questions (“Which materials?”, “Which sizes?” etc.), you’ll almost certainly really do want to use forms. This is what forms are designed for!

    In order for the following to work, I suggest you reverse how your ForeignKeys are defined; I assume you want the same material used in multiple products, not the other way ’round! Add a field like material = models.ForeignKey(Material, related_name='products') to your Product, and delete the product field from Material etc.

    Using forms might end up being pretty easy in your situation. Check out the “Creating forms from models” documentation, and try something like the following:

    # urls.py
    from django.views.generic import CreateView
    
    urlpatterns = patterns('', ...
        url(r'^(?P<pk>\d+)/$', CreateView.as_view(
            model = Product,
            template_name = "add_product.html"
        )),
    )
    

    This would get you the default Select widget — the “Creating forms from models” documentaiton (above) has information on customising the widget used to draw form fields. You would need to create a new form (inheriting from ModelForm) and point your view at that form:

    # forms.py
    from django import forms
    
    from catalogue.models import Product
    
    class ProductForm(forms.ModelForms):
        class Meta:
            model = Product 
            widgets = {
                'material': forms.RadioSelect()
                ...
            }
    
    # urls.py
    
    from catalogue.forms import ProductForm
    
    # add the following parameter to your call to as_view():
    ...
        'form_class': ProductForm
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I would like to count the length of a string with PHP. The string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.