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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:39:13+00:00 2026-05-25T21:39:13+00:00

i am kinda new to database design, but i would like to create three

  • 0

i am kinda new to database design, but i would like to create three tables “User” and “Review” and “Topic” for a database in django.

I will try to explain it in detail here:

For example, I have User, Topic and Review models in models.py. one user can only write one review for one topic from other users.

let’s say: Mike, John, Peter are the three Users.

Mike posted “Hello World” topic. John can only write one review for the topic “Hello World”, Peter can also write one review for the same. John and Peter can not post another review for the same topic(they can only modify it). If Mike post another topic, John and Peter can post another review for the new topic. the same rule apply to other users.

please if you could, could you please provide some sample code for this issue? thanks a lot.

  • 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-25T21:39:13+00:00Added an answer on May 25, 2026 at 9:39 pm

    If you are trying to figure out how to set up your models.py, visit the django documentation, and look at Writing your first app (https://docs.djangoproject.com/en/dev/intro/tutorial01/). It goes from start to finish writing your first application and you will learn how the system works.

    If you wanted more specifics for the paradigm of your case, here’s what I would do. I would probably handle this in the view/template and submit/edit the review with Dajaxice calls to the database. If a review by the current user exists, it will show the data, if it doesn’t it will be a blank entry that will use Dajax to submit the content. In the python method that the Dajax calls, you would try to find a review, and if one exists while attempting to add a new one, something went wrong and you can handle the error, otherwise it is saved for all to see.

    For example, in models.py:

    class User(models.Model):
        name = models.CharField(max_length=128)
        def __unicode__(self):
            return self.name
    
    class Review(models.Model):
        title = models.CharField(max_length=64)
        message = models.TextField()
        topic = models.ForeignKey(Topic)
        user = models.ForeignKey(User)
        def __unicode__(self):
            return self.title
    
    class Topic
        title = models.CharField(max_length=64)
        message = models.TextField()
        user = models.ForeignKey()
        def __unicode__(self):
            return self.title
    

    in views.py:

    class Post(models.Model): # This is defined a model, but not part of the data layer, it really is view code.
        topic = None
        your_review = None
        other_reviews = None
        def __unicode__(self):
            return ''
    
    def GetDetails(request):
        posts = () # to be returned to and looped by the Template.
        topics = Topic.objects.all().order_by('-posting_date') # posting_date descending.
    
        for t in topics:
            post = Post()
            post.topic = t
            post.your_review = Review.objects.filter(topic__id=t.id, user__id=<current_user_id>)
            post.other_reviews = Review.objects.filter(topic__id=t.id, ~Q(user__id=<current_user_id>)
    
            # Append to the posts array.
            posts.append(post)
    
        return render_to_response('index.htm', {'posts': posts}, context_instance=RequestContext(request))
    

    in your index.htm:

    {% if posts %}
        {% for p in posts %}
            <div>
                <div class="title">{{ p.topic.title }}</div>
                <div class="message">{{ p.topic.message }}</div>
                <div class="other_reviews">
                    {% if p.other_reviews %}
                        {% for r in p.other_reviews %}
                            <div class="review_title">{{ r.title }}</div>
                            <div class="review_message">{{ r.message }}</div>
                        {% endfor %}
                    {% endif %}
    
                    <div>
                        <input type="text" value="{% if p.your_review %}{{ p.your_review.title }}{% endif %}">
                    </div>
                    <div>
                        <textarea>{% if p.your_review %}{{ p.your_review.message }}{% endif %}</textarea>
                    </div>
                </div>
            </div>
        {% endfor %}
    {% endif %}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to database design and I considering implementing something that will be time
I am kinda new to database designing so i ask for some advices or
So, I am kinda new to ASP.net development still, and I already don't like
I new in database design. I have a question with my own few solution,
i'm kinda new in web programming, i'm trying to design a search page. i
Goodmorning everybody! I'm not completely new to PHP as in self but still kinda
I'm new to web development and database design, and I'm kind of stumped as
I'm new to Django and Web programming in general. Have googled but could not
I'm kinda new to using Rails, and an app I am working on is
I'm kinda new to Java, so haven't yet fully grasped the concept of multithreading.I

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.