Hi Coulson,

Okay, I'll give you some feedback as to the code you have written below:

   - The design below means that the actual questions are assigned to a
   fixed column in the database, this is *NOT* good. You want to be using a
   'normalized' approach, by having the questions for the poll in
   a separate table, then the answers/session stored in another.

   By using the above, the code then becomes "reusable" and easily
   maintainable.

   - Good use of string formatting (using %s rather than string concat).


Hope this helps.

Cal

On Mon, Jun 27, 2011 at 11:30 AM, Coulson Thabo Kgathi
<zeeco...@gmail.com>wrote:

> ok
>
> #models.py file
>
> from django.db import models
> from django.forms import ModelForm
> from django import forms
> from choices import YESNO, AGE, OPTIONS1, OPTIONS2, OPTIONS3, OPTIONS4,
> OPTIONS5, OPTIONS6, OPTIONS7, OPTIONS8, OPTIONS9, OPTIONS10, OPTIONS11,
> OPTIONS14, OPTIONS15, OPTIONS16, OPTIONS17, OPTIONS18, OPTIONS19
>
>
>
> class Questxs(models.Model):
>
>
>     quest1 = models.CharField(
>         verbose_name = '1. Have you ever had sexual intercourse?',
>         blank = False,
>         choices = YESNO,
>         max_length = 5,
>     )
>
>     quest2 = models.CharField(
>         verbose_name = '2. At what age did you begin sexual intercuorse?',
>         blank = False,
>         choices = AGE,
>         max_length = 5,
>         null = True,
>     )
>
>
>     quest3 =models.CharField(
>         verbose_name = '3. When was the last time you had sexual
> intercourse?',
>         blank = False,
>         choices = OPTIONS1,
>         max_length = 25,
>         null=True
>     )
>
>     quest4 = models.CharField(
>         verbose_name = '4. What decription best fits this person',
>         blank = False,
>         choices = OPTIONS2,
>         max_length = 25,
>         null = True
>     )
>
>     quest5 = models.CharField(
>         verbose_name = '5. Is this partner older or younger than you?',
>         blank = False,
>         choices = OPTIONS3,
>         max_length = 25,
>         null = True
>     )
>
>     quest6 = models.CharField(
>         verbose_name = '6. When did you first have sexual intercourse with
> your most recent partner?',
>         blank = False,
>         choices = OPTIONS4,
>         max_length = 25,
>         null = True
>     )
>
>     quest7 = models.CharField(
>         verbose_name = '7. When did you last have sexual intercourse with
> this person?',
>         blank = False,
>         choices = OPTIONS4,
>         max_length = 25,
>         null = True,
>     )
>
>     quest8 = models.CharField(
>         verbose_name = '8. The last time you had sexual intercourse with
> this partner, did you or this partner use a condom? ',
>         blank = False,
>         choices = YESNO,
>         max_length = 25,
>         null = True
>     )
>
>     quest9 = models.CharField(
>         verbose_name = '9. Do you have children with this person? ',
>         blank = False,
>         choices = OPTIONS5,
>         max_length = 25,
>         null = True,
>     )
>
>     quest10 = models.CharField(
>         verbose_name = '10. Are you still having sex with this person?',
>         blank = False,
>         choices = YESNO,
>         max_length = 25,
>         null = True
>     )
>
>     quest11 = models.CharField(
>         verbose_name = '11. How often do you have sex with this person?',
>         blank = False,
>         choices = OPTIONS6,
>         max_length = 25,
>         null = True
>     )
>
>     quest12 = models.CharField(
>         verbose_name = '12. Do you have sex with this person because you
> want to or because you feel you have to?',
>         blank = False,
>         choices = OPTIONS7,
>         max_length = 25,
>         null = True
>     )
>
>     quest13 = models.CharField(
>         verbose_name = '13. Has he/she ever assisted you either with
> financial or material support?',
>         blank = False,
>         choices = OPTIONS8,
>         max_length = 25,
>         null = True
>     )
>
>     quest14 = models.CharField(
>         verbose_name = '14. Do you know or believe that this person has
> other sexual partners?',
>         blank = False,
>         choices = OPTIONS9,
>         max_length = 25,
>         null = True
>     )
>
>     quest15 = models.CharField(
>         verbose_name = '15. Do you know the HIV status of this partner?',
>         blank = False,
>         choices = OPTIONS10,
>         max_length = 25,
>         null = True
>     )
>
>     quest16 = models.CharField(
>         verbose_name = '16. Where does this person live relative to your
> primary residence?',
>         blank = False,
>         choices = OPTIONS11,
>         max_length = 25,
>         null = True
>     )
>
>     quest17 = models.CharField(
>         verbose_name = '17. Were you and/or your partner drunk or on drugs
> the last time you had sex?',
>         blank = False,
>         choices = YESNO,
>         max_length = 5,
>     )
>
>     quest18 = models.CharField(
>         verbose_name = '18. Have you had any other sexual partners in the
> past 12 months?',
>         blank = False,
>         choices = YESNO,
>         max_length = 25,
>         null = True
>     )
>
>     quest19 = models.CharField(
>         verbose_name = '19. Have you had any other sexual partners in the
> past 12 months?',
>         blank = False,
>         choices = YESNO,
>         max_length = 25,
>         null = True
>     )
>
>     quest20 = models.CharField(
>         verbose_name = '20. In the last 12 months with how many people
> OVERALL have you had sexual intercourse, including the last 3 partners we
> have discussed?',
>         blank = False,
>         choices = OPTIONS14,
>         max_length = 25,
>         null = True
>     )
>
>     quest21 = models.CharField(
>         verbose_name = '21. In the last one month with how many people
> OVERALL have you had sexual intercourse?',
>         blank = False,
>         choices = OPTIONS15,
>         max_length = 25,
>         null = True
>     )
>
>     quest22 = models.CharField(
>         verbose_name = '22. How often do you have a drink containing
> alcohol? (in a week or in a month)',
>         blank = False,
>         choices = OPTIONS16,
>         max_length = 25,
>         null = True
>     )
>
>     quest23 = models.CharField(
>         verbose_name = '23. How much alcohol do you drink on a typical day
> when you are drinking? (instructions specify by type of alcohol and size of
> container)',
>         blank = False,
>         choices = OPTIONS17,
>         max_length = 25,
>         null = True
>     )
>
>
>     quest24 = models.CharField(
>         verbose_name = '24. How often do you have six or more units of
> alcohol on one occasion?',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest25 = models.CharField(
>         verbose_name = '25. How often during the last year have you found
> that you were not able to stop drinking once you had started?',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest26 = models.CharField(
>         verbose_name = '26. How often during the last year have you failed
> to do what was normally expected from you because of drinking?',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest27 = models.CharField(
>         verbose_name = '27. How often during the last year have you needed
> a first drink in the morning to get yourself going after a heavy drinking
> session?',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest28 = models.CharField(
>         verbose_name = '28. How often during the last year have you had a
> feeling of guilt or remorse after drinking?',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest29 = models.CharField(
>         verbose_name = '29. How often during the last year have you been
> unable to remember what happened the night before because you had been
> drinking? ',
>         blank = False,
>         choices = OPTIONS18,
>         max_length = 25,
>         null = True
>     )
>
>     quest30 = models.CharField(
>         verbose_name = '30. Have you or someone else been injured as a
> result of your drinking? ',
>         blank = False,
>         choices = OPTIONS19,
>         max_length = 25,
>         null = True
>     )
>
>     quest31 = models.CharField(
>         verbose_name = '31. Has a relative or friend or doctor or another
> health worker been concerned about your drinking or suggested you cut down?
> ',
>         blank = False,
>         choices = OPTIONS19,
>         max_length = 25,
>         null = True
>     )
>
>     def __unicode__(self):
>         return "Questionnaire %s" % (self.id)
>
> #admin.py
>
> from django.contrib import admin
> from models import Questxs
>
> class QuestxsAdmin(admin.ModelAdmin):
>     radio_fields = {
>
>         "quest1": admin.VERTICAL,
>         "quest2": admin.VERTICAL,
>         "quest3": admin.VERTICAL,
>         "quest4": admin.VERTICAL,
>         "quest5": admin.VERTICAL,
>         "quest6": admin.VERTICAL,
>         "quest7": admin.VERTICAL,
>         "quest8": admin.VERTICAL,
>         "quest9": admin.VERTICAL,
>         "quest10": admin.VERTICAL,
>         "quest11": admin.VERTICAL,
>         "quest12": admin.VERTICAL,
>         "quest13": admin.VERTICAL,
>         "quest14": admin.VERTICAL,
>         "quest13": admin.VERTICAL,
>         "quest14": admin.VERTICAL,
>         "quest15": admin.VERTICAL,
>         "quest16": admin.VERTICAL,
>         "quest17": admin.VERTICAL,
>         "quest18": admin.VERTICAL,
>         "quest19": admin.VERTICAL,
>         "quest20": admin.VERTICAL,
>         "quest21": admin.VERTICAL,
>         "quest22": admin.VERTICAL,
>         "quest23": admin.VERTICAL,
>         "quest24": admin.VERTICAL,
>         "quest25": admin.VERTICAL,
>         "quest26": admin.VERTICAL,
>         "quest27": admin.VERTICAL,
>         "quest28": admin.VERTICAL,
>         "quest29": admin.VERTICAL,
>         "quest30": admin.VERTICAL,
>         "quest31": admin.VERTICAL,
>
>     }
>
> admin.site.register(Questxs, QuestxsAdmin)
>
>
>
>
> #choices.py
>
> YESNO = (
>     ('1', 'Yes'),
>     ('0', 'No'),
> )
>
> AGE = (
>     ('<=20', '<=20'),
>     ('21-30', '21-30'),
>     ('31-40', '31-40'),
>     ('>=40', '>=40'),
> )
>
> OPTIONS1 = (
>     ('In the last 12 months', 'In the last 12 months'),
>     ('13-14 months ago', '13-14 months ago'),
>     ('>24 months ago', '>24 months ago'),
>
> )
>
> OPTIONS2 = (
>     ('Spouse', 'Spouse'),
>     ('Steady partner who lives with you/cohabitating partner', 'Steady
> partner who lives with you/cohabitating partner'),
>     ('Steady partner not living with you', 'Steady partner not living with
> you'),
>     ('Casual acquintance', 'Casual acquintance'),
>     ('Sex worker', 'Sex worker'),
>     ('Other', 'Other'),
>     ('Dont know', 'Dont know'),
>     ('No response', 'No response'),
>
> )
>
> OPTIONS3 = (
>     ('<1 year younger', '<1 year younger'),
>     ('2-3 years younger', '2-3 years younger'),
>     ('4-5 years younger', '4-5 years younger'),
>     ('6-10 years younger', '6-10 years younger'),
>     ('<1 year older', '<1 year older'),
>     ('2-3 years older', '2-3 years older'),
>     ('4-5 years older', '4-5 years older'),
>     ('6-10 years older', '6-10 years older'),
> )
>
> OPTIONS4 = (
>     ('days ago', 'days ago'),
>     ('weeks ago', 'weeks ago'),
>     ('months ago', 'months ago'),
>     ('years ago','years ago'),
> )
>
>
> OPTIONS5 = (
>     ('No','No'),
>     ('yes,one child','yes, one child'),
>     ('yes, more than one child','yes, more than one child'),
>     ('Dont know','Dont know'),
>     ('No response','No response'),
> )
>
> OPTIONS6 = (
>     ('Days per week','Days per week'),
>     ('Days per month','Days per month'),
>     ('Days per year','Days per year'),
>     ('Only once', 'Only once'),
>     ('When i am in the mood i will see him/her', 'When i am in the mood i
> will see him/her'),
>     ('When i am in town', 'When i am in town'),
>     ('When i am fighting with my main partner', 'When i am fighting with my
> main partner'),
>     ('When i happen to see him/her, we end having sex', 'When i happen to
> see him/her, we end having sex'),
>     ('When there  is no one else available', 'When there  is no one else
> available'),
>     ('When i need somethimg from him/her', 'When i need somethimg from
> him/her'),
>     ('When i am broke', 'When i am broke'),
>     ('Other', 'Other'),
>     ('Dont know', 'Dont know'),
>     ('No response', 'No response'),
>
> )
>
>
> OPTIONS7 = (
>     ('want to','want to'),
>     ('have to', 'have to'),
>     ('Dont know/not sure','Dont know/not sure'),
>     ('No response', 'No response')
> )
>
> OPTIONS8 = (
>     ('No', 'No'),
>     ('Yes, rarely', 'Yes, rarely'),
>     ('Yes, occasionally', 'Yes, occasionally'),
>     ('Yes, frequently', 'Yes, frequently'),
>     ('Dont know', 'Dont know'),
>     ('No response', 'No response'),
> )
>
> OPTIONS9 = (
>     ('No dosent have', 'No dosent have'),
>     ('Not sure', 'Not sure'),
>     ('Yes, I KNOW he/ she has other partners', 'Yes, I KNOW he/ she has
> other partners'),
>     ('Yes I BELIEVE he/she has other partners', 'Yes I BELIEVE he/she has
> other partners'),
>     ('No response','No response'),
> )
> OPTIONS10 = (
>     ('No','No'),
>     ('Yes and the partner has HIV','Yes and the partner has HIV'),
>     ('Yes and the partner doess not have HIV','Yes and the partner does not
> have  HIV'),
> )
> OPTIONS11 =(
>     ('In same household','In same household'),
>     ('In same town as primary residence','In same town as primary
> residence'),
>     ('In town where I work','In town where I work'),
>     ('In area where I travel for work','In area where I travel for work'),
>     ('In area where I travel for personal reasons','In area where I travel
> for personal reasons'),
> )
>
> OPTIONS14 = (
>     ('Three','Three'),
>     ('Four','Four'),
>     ('Five','Five'),
>     ('More','More'),
>
> )
>
>
> OPTIONS15 = (
>     ('One', 'One'),
>     ('Two', 'Two'),
>     ('Three', 'Three'),
>     ('More', 'More'),
>
> )
>
> OPTIONS16 = (
>     ('Never', 'Never'),
>     ('Monthly or less', 'Monthly or less'),
>     ('2-4 times a month', '2-4 times a month'),
>     ('2-3 times a week', '2-3 times a week'),
>     ('4 or more times a week', '4 or more times a week'),
> )
>
> OPTIONS17 = (
>     ('1 or 2', '1 or 2'),
>     ('3 or 4', '3 or 4'),
>     ('5 or 6', '5 or 6'),
>     ('7, 8 or 9', '7, 8 or 9'),
>     ('10 or more', '10 or more'),
> )
>
> OPTIONS18 = (
>     ('Never', 'Never'),
>     ('Less than monthly', 'Less than monthly'),
>     ('Monthly', 'Monthly'),
>     ('Weekly', 'Weekly'),
>     ('Almost daily', 'Almost daily')
> )
>
> OPTIONS19 = (
>     ('No', 'No'),
>     ('Yes, but not in the last year', 'Yes, but not in the last year'),
>     ('Yes, over last year', 'Yes, over last year')
> )
>
>
>
>
> #urls
>
> from django.conf.urls.defaults import *
>
> # Uncomment the next two lines to enable the admin:
> from django.contrib import admin
> admin.autodiscover()
>
> urlpatterns = patterns('',
>     # Example:
>     # (r'^questionSite/', include('questionSite.foo.urls')),
>     #(r'^questions/(?P<question_id>\d+)/$', 'questions.views.detail'),
>     # Uncomment the admin/doc line below and add 'django.contrib.admindocs'
>
>     #(r'^admin/doc/', include('django.contrib.admindocs.urls')),
>     # to INSTALLED_APPS to enable admin documentation:
>
>     # Uncomment the next line to enable the admin:
>     (r'^admin/', include(admin.site.urls)),
> )
>
>
>
>
> so this gives me a questionnaire but i kind of hard coded the question and
> i am not using my own templete but i want to use my own templete, of which i
> suppose i will nid to use the views file and may other file so that is what
> i am failing to do.
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Django users" group.
> To post to this group, send email to django-users@googlegroups.com.
> To unsubscribe from this group, send email to
> django-users+unsubscr...@googlegroups.com.
> For more options, visit this group at
> http://groups.google.com/group/django-users?hl=en.
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to