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

  • Home
  • SEARCH
  • 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 8987937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T21:54:35+00:00 2026-06-15T21:54:35+00:00

I have a class Questions(models.Model): question = models.CharField(max_length=150) created_by = models.CharField(max_length=30) def __unicode__(self): return

  • 0

I have a

class Questions(models.Model):
    question = models.CharField(max_length=150)
    created_by = models.CharField(max_length=30)
    def __unicode__(self):
        return self.question

Now i need a output like this (so i can use it like djangos {{ form.as_p }}):

<div id="question-1">The string in question"</div>
<div id="question-2">The string in another question"</div>
...

With loq = Questions.objects.filter(created_by=user) i get [<Questions: My first question!>,...] in str(loq).

Is there an easier way than to search str(loq) with .find()?

EDIT:

Solved it this way (thanks to Samuele Mattiuzzo):

models.py:

class Questions(models.Model):
    question = models.CharField(max_length=150)
    created_by = models.ForeignKey(User)
    def __unicode__(self):
        return self.question

views.py:

def ViewQuestions(request):
    if request.user.is_authenticated():
        loq = Questions.objects.filter(created_by=request.user)

        return render(request, "main/questions.html", {'loq': loq})
    else:
        return HttpResponseRedirect("/")

questions.html:

{% for q in loq %}
<div id="question-{{ forloop.counter }}">{{ q.question }}</div>
{% endfor %}
  • 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-15T21:54:36+00:00Added an answer on June 15, 2026 at 9:54 pm

    create a template file (say questions.html) like this:

    {% for q in loq %}
        <div id="question-{{ forloop.counter }}">{{ q.question }}</div>
    {% endfor %}
    

    in your views.py, you have to return your queryset (which is your loq)

    def view_questions(response, user):
        loq = Questions.objects.filter(created_by=user)
        return render_to_response(
            'questions.html',
            locals(),
            context_instance=RequestContext(request)
        )
    

    locals() is the dictionary containing your loq. here i’m assuming you already know how django works. i don’t really get what you mean with that “.find()” statement, tho.

    you may also want to change the created_by field from CharField to ForeignKey poiting to the User class

    check the docs about querysets and views for more knowledge on the subject.

    if this doesn’t answer, provide some more explanation and i’ll be updating the answer

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model class Survey(models.Model): created_by = models.ForeignKey(User) question = models.CharField(max_length=150) active =
I have two models: call them questions and answers: class FacetQuestion(models.Model): the_question = models.CharField(max_length=50)
Django beginner question. I have the following model: class Leg(models.Model): startpoint = models.CharField(max_length=50, help_text=examples:
I have the following models : class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField(auto_now_add=True)
I have the relationship follow as: class Question(models.Model): content = models.CharField(max_length=128) class Answer(models.Model): content
I have the relationship follow as: class Question(models.Model): qid = models.PositiveIntegerField(primary_key=True) content = models.CharField(max_length=128)
Let's say I have the following: class Employee(models.Model): firstName = models.CharField(max_length = 30) lastName
If you have some models: class Teacher(models.Model): name = models.CharField(max_length=50) class Student(models.Model): age =
I have a model like this class Ask(models.Model): name = models.CharField(max_length=500) designation = models.CharField(max_length=200,
Suppose i have : class Library(models.Model): name = models.CharField(max_length = 100) class Books(models.Model): library

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.