Right, I am literally about to loose my temper.
I have a Django model, with an object. I have a fucntion which generated a random ID, appends it to the model object and places it on the end of the URL.
Thats the theory anyway, but just like everything else in my life, nothing works. I have a great big neon sign that is only invisible to me which stated “Please piss this guy off as much as you possibly can!”
You have no idea how sick to death I am of this. It’s so silly! It’s so unfair and I am going to fume.
In my urls.py
I have:
“from django.urls import path, include
from . import views
urlpatterns =[
path('',views.careers, name="careers"),
path('apply/<str:careers_reference>',views.apply),
]``
In my views.py
I have:
`from django.shortcuts import render, redirect, get_object_or_404
from django.core.mail import send_mail, BadHeaderError
from django.http import HttpResponse, HttpResponseRedirect
from django.template import loader
from . models import Careers
import logging
from xxxx import utils
def apply(request, careers_reference):
career_detail = get_object_or_404(Careers,careers_reference = careers_reference)
template = loader.get_template('careers-details.html')
context = {
'career_detail' : career_detail,
}
return HttpResponse(template.render(context, request))`
In my models.py
, I have
`from django.db import models
from . import utils
# Create your models here.
REGION = {
"US":{
"Embarcadero, Palo Alto, California":"Palo Alto",
"Redwood Shores, Redwood City, California":"Redwood City",
"Dover, Kent County, Delaware" : "Dover, Delaware",
"Hybrid (US)":"Hybrid",
},
"UK":{
"Canada Square, Canary Warf, London, UK":"Canary Warf, London",
"Hybrid (UK)":"Hybrid",
},
"Remote" : "Remote",
}
DEPARTMENT = (
(‘Technical Services’, ‘Technical’),
(‘Financial Services’, ‘Finance’),
(‘Client Services’, ‘Client’),
(‘Operational Services’, ‘Operational’)
)
CONTRACT = (
(‘Permanent – Full Time’,’Permanent – Full Time’),
(‘Permanent – Part Time’,’Permanent – Part Time’),
(‘Contract – Full Time’,’Contract – Full Time’),
(‘Contract – Part Time’,’Contract – Part Time’),
(‘Contract’,’Contract’)
)
CONTACT = (
(‘xxx’,’xxx’),
(‘xxx’,’xxx’),
(‘xxx’,’xxx’),
(‘xxx’,’xxx’),
)
class Careers(models.Model):
careers_reference = models.CharField(max_length=100, default=utils.job_reference(12), unique=True,editable=False)
career_job_title = models.CharField(max_length=255)
career_job_summary = models.CharField(max_length=255)
career_department = models.CharField(max_length=255, choices=DEPARTMENT, default="technology")
career_region = models.CharField(max_length=255, choices=REGION, default='uk')
career_contact = models.CharField(max_length=255, choices=CONTACT, default='Whatever')
career_specification = models.TextField(default="", null=True)
career_contract = models.CharField(max_length=255, choices=CONTRACT, default='')
#slug = models.SlugField(default="", null=True, unique=True)
class Meta:
verbose_name_plural = "Careers"
def str(self):
return self.JobTitle`
In my utils.py, I have:
`import random, string
def job_reference(charlength):
post_reference = ”.join(random.choices(string.ascii_uppercase + string.digits, k=charlength)) # Generates a random string
return str(post_reference)`
In my admin.py
`from django.contrib import admin
from . models import Careers
class MemberAdmin(admin.ModelAdmin):
list_display = (“career_job_title”,”careers_reference”)
Register your models here.
admin.site.register(Careers, MemberAdmin)`
This is absolutely stupid, isn’t it? I swear Django has a mind of its own sometimes. Perhaps today it;s just decided “Nah, Im going to piss this bloke off because I feel like it”
Guess what, I’m in bloody charge here, and If I tell Django to do something, it bloody damn well does it.
So tired of this bullshit, day in, day out with this framework
Sold my sanity?Sold my sanity?
1