Left align | Right align | Center align |
---|---|---|
This | This | This |
column | column | column |
will | will | will |
be | be | be |
left | right | center |
aligned | aligned | aligned |
This file contains hidden or 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 myapp.utils import set_current_user | |
class CurrentUserMiddleware: | |
def process_request(self, request): | |
set_current_user(getattr(request, 'user', None)) | |
This file contains hidden or 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.db.models.signals import pre_save, post_init | |
def track_model_changes(sender, instance, **kwargs): | |
"""Save former data to compare with new data and track changed values""" | |
instance.__former = dict((field.name, field.value_from_object(instance)) for field in Report._meta.fields) | |
This file contains hidden or 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
<html> | |
<head> | |
<meta charset="utf-8" /> | |
<style> | |
body { | |
font-family: sans-serif; | |
} | |
.icon { |
This file contains hidden or 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 import forms | |
from myapp.models import MyObject | |
class MyObjectForm(forms.ModelForm): | |
class Meta: | |
model = MyObject | |
def save(self, commit=True): | |
o = super(MyObjectForm, self).save(commit=False) | |
# o.value = "pre-set value fi user" |
This file contains hidden or 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.contrib.auth.models import User | |
class LoggedTestCase(TestCase): | |
def setUp(self): | |
self.user = User.objects.create_user('admin', '[email protected]', 'pwd') | |
self.user.save() | |
self.client = Client() | |
self.client.login(username='admin', password='pwd') |