Skip to content

Instantly share code, notes, and snippets.

View mbmohib's full-sized avatar
🎯
Focusing

Mohammad Mohibbullah mbmohib

🎯
Focusing
View GitHub Profile
@mbmohib
mbmohib / forms.py
Created November 23, 2016 17:08
Checking more than one filed exist or not!
def clean(self):
try:
User.objects.get(first_name=self.cleaned_data['first_name'],
last_name=self.cleaned_data['last_name'])
raise forms.ValidationError("Exists already!")
except User.DoesNotExist:
pass
return self.cleaned_data
@mbmohib
mbmohib / forms.py
Created November 23, 2016 17:06
In registration menu, checking email already exist or not!
def clean_email(self):
email = self.cleaned_data.get('email')
username = self.cleaned_data.get('username')
if email and User.objects.filter(
email=email).exclude(username=username).count():
raise forms.ValidationError(
"A user with that email already exists")
return email
# Three methods of getting object's url:
<a href='/posts/{{ post.id }}'><p>{{ post.title }}</p></a> (#static)
<a href='{% url 'detail' id=post.id %}'><p>{{ post.title|title }}</p></a>
<a href='{{ post.get_absolute_url }}'><p>{{ post.title|title }}</p></a>