Thanks for your reply. The string is the class name according to the link u provides under Foreignkey is says "If you need to create a relationship on a model that has not yet been defined, you can use the name of the model, rather than the model object itself:" So I represented my class as a string since that model was written after I reference it.
On Friday, 14 June 2019 07:04:38 UTC-4, Joe Reitman wrote: > > Your passing strings as the first argument in your many-to-many fields. > Shouldn't they be classes? Doc > <https://www.google.com/url?q=https%3A%2F%2Fdocs.djangoproject.com%2Fen%2F2.2%2Fref%2Fmodels%2Ffields%2F%23manytomanyfield&sa=D&sntz=1&usg=AFQjCNHcES6LF8pQ5sDe-SjXBuDfDWyMjA> > > On Thursday, June 13, 2019 at 8:31:29 PM UTC-5, curtly critchlow wrote: >> >> CreateView class not saving data to database. When I hit submit, the html >> the page only refreshes. l'm not getting any errors so I have no idea what >> i'm doing wrong. Does CreateView automatically takes care of many to >> many relationships? here is my code below, I've been trying to solve this >> problem 2 days now. >> >> >> 1. Models.py >> 2. >> 3. from django.db import models >> 4. from django.utils import timezone >> 5. from django.urls import reverse_lazy, reverse >> 6. >> 7. # Create your models here. >> 8. >> 9. class Requisition(models.Model): >> 10. # constants >> 11. FROZEN = 'Frozen' >> 12. CHILLED = 'Chilled/Cold Pack' >> 13. DRYICE = 'Dry Ice' >> 14. ROOMTEMP = 'Room Temperature' >> 15. TRANSPORT_CHOICE = >> [(FROZEN,FROZEN),(CHILLED,CHILLED),(DRYICE,DRYICE),(ROOMTEMP,ROOMTEMP)] >> 16. >> 17. EMAIL = 'email' >> 18. HARDCOPY = 'Hardcopy Pickup' >> 19. BOTH = 'Email & Hardcopy Pickup' >> 20. RECEIPT_CHOICE = [(EMAIL,EMAIL), (HARDCOPY,HARDCOPY), >> (BOTH,BOTH)] >> 21. >> 22. >> 23. ACUTE = 'Acute' >> 24. CHRONIC = 'Chronic' >> 25. SYMPTOMS_CHOICE = [(ACUTE,ACUTE,), (CHRONIC,CHRONIC)] >> 26. >> 27. #columns >> 28. accession_number = models.CharField(max_length=254, >> unique=True, help_text='format: VSLXXX-XXX') >> 29. customer = models.ForeignKey('general.Customer', >> on_delete=models.CASCADE, related_name='requisition') >> 30. >> 31. # Veterinary Officer Info >> 32. veterinary_officer = models.CharField(max_length=50, >> blank=True) >> 33. address = models.CharField(max_length=50, blank=True) >> 34. contact_number = models.CharField(max_length=13, blank=True, >> help_text="number format example: +592 XXX XXXX") >> 35. email_address = models.EmailField(max_length=50, blank=True) >> 36. >> 37. # General sample info >> 38. >> 39. collected_by = models.CharField(max_length=50) >> 40. time_of_collection = models.DateTimeField() >> 41. >> 42. >> 43. method_of_transport = models.CharField(max_length=50, >> choices=TRANSPORT_CHOICE) >> 44. result_transmission = models.CharField(max_length=50, >> choices=RECEIPT_CHOICE) >> 45. >> 46. #pathology >> 47. reason_for_request = >> models.ManyToManyField('ReasonForRequest',related_name='requisition', >> blank=True) >> 48. illness_date = models.DateField('Date of onset of illness', >> blank=True, null=True) >> 49. illness_duration = models.CharField('Duration of illness', >> max_length=254, blank=True) >> 50. symptoms = models.CharField(max_length=50, >> choices=SYMPTOMS_CHOICE, blank=True) >> 51. fever = models.BooleanField('Presence of Fever', blank=True, >> null=True) >> 52. body_temp = models.PositiveSmallIntegerField('Max body >> Temperature (C)', blank=True, null=True) >> 53. fever_duration = models.CharField('Duration of >> Fever',max_length=50, blank=True) >> 54. signs = models.ManyToManyField('Signs', >> related_name='requisition', blank=True) >> 55. vaccination_status = models.CharField(max_length=50, >> blank=True) >> 56. vaccination_date = models.DateField('Date of Vaccination', >> blank=True, null=True) >> 57. treatments = models.TextField('Previous/Current Treatments', >> blank=True) >> 58. exposed = models.ManyToManyField('Exposed', >> related_name='requisition', through='ExposureHistory', blank=True) >> 59. >> 60. comments = models.TextField(blank=True) >> 61. recieved_by = models.ForeignKey('auth.User', >> on_delete=models.CASCADE) >> 62. submitted_by = models.CharField(max_length=254, help_text='if >> multiple persons separate names using "&" exampe: John Doe >> & >> Jane Doe') >> 63. date_of_submission = models.DateTimeField(auto_now_add=True) >> 64. >> 65. def __str__(self): >> 66. return self.accession_number >> 67. >> 68. def get_absolute_url(self): >> 69. return reverse("laboratory:requisition_details", >> kwargs={'pk':self.pk}) >> 70. >> 71. forms.py >> 72. >> 73. from django.forms import ModelForm >> 74. from general.models import Customer >> 75. from laboratory.models import Requisition >> 76. from bootstrap_datepicker_plus import DatePickerInput, >> DateTimePickerInput >> 77. >> 78. class RequisitionForm(ModelForm): >> 79. class Meta: >> 80. model = Requisition >> 81. fields = '__all__' >> 82. widgets = { >> 83. 'illness_date': DatePickerInput, >> 84. 'vaccination_date': DatePickerInput, >> 85. 'date_of_submission': DateTimePickerInput, >> 86. } >> 87. views.py >> 88. from django.contrib.auth.mixins import LoginRequiredMixin >> 89. from django.urls import reverse_lazy, reverse >> 90. from django.shortcuts import render >> 91. from django.views.generic import TemplateView, CreateView, >> DetailView, ListView, UpdateView, DeleteView >> 92. from general.models import Customer >> 93. from laboratory.models import Requisition, Sample >> 94. from laboratory.forms import RequisitionForm >> 95. # Create your views here. >> 96. >> 97. class RequisitionListView(LoginRequiredMixin, ListView): >> 98. model = Requisition >> 99. context_object_name = 'requisition_list' >> 100. template_name ='laboratory/requisition_list.html' >> 101. >> 102. class RequisitionDetailView(DetailView): >> 103. model = Requisition >> 104. context_object_name = 'requisition_details' >> 105. template_name='laboratory/requisition_details.html' >> 106. >> 107. class RequisitionCreateView(LoginRequiredMixin, CreateView): >> 108. model = Requisition >> 109. form_class= RequisitionForm >> 110. template_name = 'laboratory/requisition_create.html' >> 111. >> 112. requisition_create.html >> 113. {% extends "user_home.html" %} >> 114. {% load static %} >> 115. {% load widget_tweaks %} >> 116. {% load bootstrap4 %} >> 117. {% bootstrap_css %} >> 118. {% bootstrap_javascript jquery='full' %} >> 119. {{ form.media }} >> 120. >> 121. {% block form %} >> 122. <div class="main jumbotron"> >> 123. <h1>Complete Requisition form below</h1> >> 124. <p></p> >> 125. <form method="POST"> >> 126. {% csrf_token %} >> 127. <div class='row'> >> 128. <div class='col'> >> 129. <div class="card"> >> 130. <div class="card-header"> >> 131. General Information >> 132. </div> >> 133. <div class="card-body fieldwrapper form-group"> >> 134. {{ form.accession_number.errors }} >> 135. {{ form.accession_number.label_tag }} >> 136. {{ form.accession_number|add_class:"form-control" }} >> 137. <p></p> >> 138. {{ form.customers.errors }} >> 139. {{ form.customer.label_tag }} >> 140. {{ form.customer|add_class:"form-control" }} >> 141. <p></p> >> 142. {{ form.collected_by.errors }} >> 143. {{ form.collected_by.label_tag }} >> 144. {{ form.collected_by|add_class:"form-control" }} >> 145. <p></p> >> 146. {{ form.recieved_by.errors }} >> 147. {{ form.recieved_by.label_tag }} >> 148. {{ form.recieved_by|add_class:"form-control" }} >> 149. <p></p> >> 150. {{ form.submitted_by.errors }} >> 151. {{ form.submitted_by.label_tag }} >> 152. {{ form.submitted_by|add_class:"form-control" }} >> 153. <p></p> >> 154. {{ form.date_of_submission.errors }} >> 155. {{ form.date_of_submission.label_tag }} >> 156. {{ form.date_of_submission|add_class:"form-control" }} >> 157. >> 158. </div> >> 159. </div> >> 160. </div> >> 161. >> 162. <p></p> >> 163. <div class="col"> >> 164. <div class="card"> >> 165. <div class='card-header'> >> 166. Veterinarian/Leo/Lea Information >> 167. </div> >> 168. <div class="card-body"> >> 169. {{ form.veterinary_officer.errors }} >> 170. {{ form.veterinary_officer.label_tag }} >> 171. {{ form.veterinary_officer|add_class:"form-control" }} >> 172. <p></p> >> 173. {{ form.address.errors }} >> 174. {{ form.address.label_tag }} >> 175. {{ form.address|add_class:"form-control" }} >> 176. <p></p> >> 177. {{ form.contact_number.errors }} >> 178. {{ form.contact_number.label_tag }} >> 179. {{ form.contact_number|add_class:"form-control" }} >> 180. <p></p> >> 181. {{ form.email_address.errors }} >> 182. {{ form.email_address.label_tag }} >> 183. {{ form.email_address|add_class:"form-control" }} >> 184. </div> >> 185. </div> >> 186. </div> >> 187. >> 188. </div> >> 189. >> 190. <p></p> >> 191. >> 192. <div class="card"> >> 193. <div class='card-header'> >> 194. Transmission Information >> 195. </div> >> 196. <div class="card-body"> >> 197. {{ form.method_of_transport.errors }} >> 198. {{ form.method_of_transport.label_tag }} >> 199. {{ form.method_of_transport|add_class:"form-control" }} >> 200. <p></p> >> 201. {{ form.result_transmission.errors }} >> 202. {{ form.result_transmission.label_tag }} >> 203. {{ form.result_transmission|add_class:"form-control" }} >> 204. >> 205. </div> >> 206. </div> >> 207. <p></p> >> 208. <div class="card"> >> 209. <div class='card-header'> >> 210. Pathology Information >> 211. </div> >> 212. <div class="card-body row"> >> 213. <div class='col'> >> 214. {{ form.reason_for_request.errors }} >> 215. {{ form.reason_for_request.label_tag }} >> 216. {{ form.reason_for_request|add_class:"form-control" >> }} >> 217. <p></p> >> 218. {{ form.illness_date.errors }} >> 219. {{ form.illness_date.label_tag }} >> 220. {{ form.illness_date|add_class:"form-control" }} >> 221. <p></p> >> 222. {{ form.symptoms.errors }} >> 223. {{ form.symptoms.label_tag }} >> 224. {{ form.symptoms|add_class:"form-control" }} >> 225. <p></p> >> 226. {{ form.fever.errors }} >> 227. {{ form.fever.label_tag }} >> 228. {{ form.fever|add_class:"form-control" }} >> 229. <p></p> >> 230. {{ form.body_temp.errors }} >> 231. {{ form.body_temp.label_tag }} >> 232. {{ form.body_temp|add_class:"form-control" }} >> 233. <p></p> >> 234. {{ form.fever_duration.errors }} >> 235. {{ form.fever_duration.label_tag }} >> 236. {{ form.fever_duration|add_class:"form-control" }} >> 237. <p></p> >> 238. </div> >> 239. >> 240. <div class='col'> >> 241. {{ form.signs.errors }} >> 242. {{ form.signs.label_tag }} >> 243. {{ form.signs|add_class:"form-control" }}<p></p> >> 244. <p></p> >> 245. {{ form.vaccination_status.errors }} >> 246. {{ form.vaccination_status.label_tag }} >> 247. {{ form.vaccination_status|add_class:"form-control" }} >> 248. <p></p> >> 249. {{ form.vaccination_date.errors }} >> 250. {{ form.vaccination_date.label_tag }} >> 251. {{ form.vaccination_date|add_class:"form-control" }} >> 252. <p></p> >> 253. {{ form.treatments.errors }} >> 254. {{ form.treatments.label_tag }} >> 255. {{ form.treatments|add_class:"form-control" }} >> 256. <p></p> >> 257. {{ form.exposed.errors }} >> 258. {{ form.exposed.label_tag }} >> 259. {{ form.exposed|add_class:"form-control" }} >> 260. </div> >> 261. </div> >> 262. </div> >> 263. <p></p> >> 264. {{ form.comments.errors }} >> 265. {{ form.comments.label_tag }} >> 266. {{ form.comments|add_class:"form-control" }} >> 267. <p></p> >> 268. >> 269. <input type="submit" class='btn btn-primary' value='Submit'> >> 270. >> 271. >> 272. </form> >> 273. </div> >> 274. >> 275. {% endblock form %} >> >> >> >> -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscr...@googlegroups.com. To post to this group, send email to django-users@googlegroups.com. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3d95c287-32d8-43e7-a9f8-bfa7107e0d0b%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.