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 6049347
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:34:00+00:00 2026-05-23T07:34:00+00:00

i have a model called mti(Material Information) which have a list of MTD(Material Description)

  • 0

i have a model called mti(Material Information) which have a list of MTD(Material Description) and in each material description description there is a size and color

i have an MTI id i want to get all the distinct list of color values
mymti = mti.objects.get(pk=1)

how can i get the list of colors from MTI
mymti.mtd.color.name ?

class color(models.Model):
id = models.AutoField(primary_key=True)
name= models.CharField(max_length=255)
stamp= models.DateTimeField(auto_now=True)
def __unicode__(self):
    return self.name
class mtd(models.Model):
id = models.AutoField(primary_key=True)
barcode = models.CharField(max_length=255)
#mti = models.ManyToManyField(mti)
size = models.ForeignKey(size)
color = models.ForeignKey(color)
weight = models.FloatField()
def __unicode__(self):
    return u'%s - %s %s' % (self.barcode,self.color.name,self.size.name)
class Meta:
    verbose_name = "MTD"
    verbose_name_plural = verbose_name



class mti(models.Model):
id = models.AutoField(primary_key=True)
name = models.CharField(max_length=255)
item = models.ForeignKey(item)
mtd= models.ManyToManyField(mtd)
country = models.ForeignKey(country)
dept = models.ForeignKey(dept)
fabric = models.ForeignKey(fabric)
sesason = models.ForeignKey(season)
sale = models.FloatField()
endUser = models.FloatField()
description = models.TextField(max_length=1000,blank=True,null=True)
year = models.CharField(max_length=255,default=strftime("%Y", gmtime()))
front_page = models.BooleanField(verbose_name="Front Page",default=True)
active = models.BooleanField(default=True)
stamp = models.DateTimeField(auto_now=True)
def __unicode__(self):
    return u'%s - %s' % (self.name, self.description)
class Meta:
    verbose_name = "MTI"
    verbose_name_plural = verbose_name

class mtiimage(models.Model):
id = models.AutoField(primary_key=True)
mtd = models.ManyToManyField(mtd)
image1 = models.ImageField(verbose_name="Product 1 Image",upload_to='product')
image2 = models.ImageField(verbose_name="Product 2 Image",upload_to='product')
image3 = models.ImageField(verbose_name="Product 3 Image",upload_to='product')
stamp = models.DateTimeField(auto_now=True)

def admin_thumbnail(self):
    return u'<img src="%s" heigh="150" width="200" />' % (self.image1.url)
admin_thumbnail.short_description = 'Thumbnail'
admin_thumbnail.allow_tags = True
def __unicode__(self):
    return u'%s ' % (self.id)
class Meta:
    verbose_name = "MTI Image"
    verbose_name_plural = verbose_name
  • 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-05-23T07:34:01+00:00Added an answer on May 23, 2026 at 7:34 am

    Annotation

    Use annotation.

    mymti = mti.objects.get(pk=1)
    unique_colors = mymti.mtd.values_list('color__name', flat=True).annotate()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model called Profile which is belong_to User, so there is 'user_id'
I have a model called Tournament, which has_many Entries. There is a method in
I have a model called Contact which has_one guest like so. class Contact <
I have a model called Answer which has a ForeignKey relationship to another model
Have a model called contact_email.date_sent I want to be able to run a report
I have a model called Category which looks like this: class Category < ActiveRecord::Base
I have a model called a voip_phone that has a an attribute schedule which
I have a Model called Section which has many articles ( Article ). These
I have a model called User, and a user has a property relatedUsers, which,
I have a model called User , and another called Run . Each user

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.