This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxSetup({ | |
data: {csrfmiddlewaretoken: '{{ csrf_token }}' }, | |
}); | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$.ajaxSetup({ | |
beforeSend: function(xhr, settings) { | |
function getCookie(name) { | |
var cookieValue = null; | |
if (document.cookie && document.cookie != '') { | |
var cookies = document.cookie.split(';'); | |
for (var i = 0; i < cookies.length; i++) { | |
var cookie = jQuery.trim(cookies[i]); | |
Does this cookie string begin with the name we want? |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
function ButtonSearchClick() { | |
$.ajax({ | |
type: 'POST', | |
url: "{% url 'your_django_url_name_goes_here' %}", | |
success: function (response) { | |
// on successfull creating object | |
// your logic goes here | |
}, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="form-group mb-3"> | |
<textarea id="textAreaId" rows="10" cols="20" class="form-control"></textarea> | |
</div> | |
<div class="form-group"> | |
<input id="btn_ajax_post" type="button" value="Ajax Post To Django" onclick="ButtonSearchClick()"> | |
</div> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import string, random | |
from django.utils.text import slugify | |
def random_string_generator(size=10, chars=string.ascii_lowercase + string.digits): | |
return ''.join(random.choice(chars) for _ in range(size)) | |
def unique_slug_generator(instance, new_slug=None): | |
if new_slug is not None: | |
slug = new_slug | |
else: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from django.dispatch import receiver | |
from django.db.models.signals import pre_save | |
from .utils import unique_slug_generator | |
class SomeModel(models.Model): | |
title = models.CharField(max_length=400) | |
slug = models.SlugField(max_length=400, null=True, blank=True, unique=True) | |
def __str__(self): |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
import os | |
import re | |
def download_button(self): | |
query = """select registration_no as "Registration No.", name as "Student", father_name as "Father Name", login as "Login" | |
from some_table | |
where id = %s | |
order by registration_no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<odoo> | |
<data noupdate="0"> | |
<record id="your_sequence_number_xml_id_goes_here" model="ir.sequence"> | |
<field name="name">Your Sequence Name</field> | |
<field name="code">your_sequence_number_code_goes_here</field> | |
<field name="prefix">%(y)s%(month)s%(day)s-</field> | |
<field eval="1" name="number_next"/> | |
<field eval="1" name="number_increment"/> | |
<field eval="True" name="use_date_range"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<odoo> | |
<data noupdate="0"> | |
<record id="your_sequence_number_xml_id_goes_here" model="ir.sequence"> | |
<field name="name">Student Transport Registration Service</field> | |
<field name="code">your_sequence_number_code_goes_here</field> | |
<field name="prefix">%(y)s-</field> | |
<field eval="1" name="number_next"/> | |
<field eval="1" name="number_increment"/> | |
<field eval="True" name="use_date_range"/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<odoo> | |
<data noupdate="0"> | |
<record id="your_sequence_number_xml_id_goes_here" model="ir.sequence"> | |
<field name="name">Your Sequence Name</field> | |
<field name="code">your_sequence_number_code_goes_here</field> | |
<field name="prefix">%(y)s%(month)s-</field> | |
<field eval="1" name="number_next"/> | |
<field eval="1" name="number_increment"/> | |
<field eval="True" name="use_date_range"/> |