Red/library/jslider/Makefile at master · friendica/red. 11 Things I Wish I Knew About Django Development Before I Started My Company: — CS + Math. Tutorial: Using Django's Multiple Database Support. In a recent Django class one of my students posed the problem she was learning Django to tackle - she would be responsible for writing a web-based administrative interface to a database whose structure she wasn't allowed to modify. Can Django do that? Absolutely - and Django even comes with a management command to bootstrap working with a legacy database. Let's create a brand new project, use a popular sample database as our target, and using Django's multi-db support to store Django's built-in model data in a separate database. Installation and setup For this project I'm using Django 1.3 since that's the version we targeted in the class.
. $ mkdir dualdb-project $ cd dualdb-project $ mkvirtualenv django1.3 (django1.3)$ pip install django==1.3 ... Now that I have a new Django project, I need a sample database to look at. (django1.3)$ cd dualdb/ (django1.3)$ chmod u+x manage.py (django1.3)$ . Multi-database setup Django has builtin support for multiple databases. (django1.3)$ . Database routers.
Render placeholder to template variable. Cmsplugin-text-ng 0.3. An enhanced version of the Text plugin for django CMS. It allows wrapping the text plugin inside a template selectable by the CMS content editor. Note This plugin is not meant to replace cms.plugins.text. It is an enhancement for certain use cases. For most types of content, you should probably still use cms.plugins.text or write a specifically tailored plugin. Add cmsplugin_text_ng to your INSTALLED_APPS.Create some templates (more on that soon) and add them in the admin. Basic example: static template Let's say you want to have a text plugin with a facebook "like" button. <div class="text left"> {{ body|safe }} </div><div class="fb-like right"><h2>Like this page on facebook!
Advanced example: dynamic template Let's assume you want to set the content of the <h2>-tag on a per-plugin basis. When you edit the plugin, you will now have a text box with the "h2_content" as a label. Really (just kidding) advanced example: define your own types A couple of things to note: Where were we? Done. Profiles. The Perfect Django Settings File. I know this isn't the best way to start an article, but I lied. This article won't show you how to make the perfect Django settings file. Instead, it will show you how to build the perfect Django settings module. When I'm first starting a new Django project, I like to make sure that my settings file(s) are crafted in an organized, ideal manner. My settings file(s) should allow me to: Maintain as many specific deployment environment settings as I choose in a clear and separate manner.
Old Habits Die Hard I'd like to quickly discuss why I think most people design their settings file(s) wrong. The approach to settings that I see many people take is simplistic--they'll define all of their values in their settings.py file, and then at the bottom of the file write something like this: try: from settings_local import *except ImportError: pass Don't version control the settings_local.py files on your various servers. There is a better way! Write a Settings Module. Filter - Django Admin Custom Change List Arguments: Override /?e=1. Where Django Caching Bust at the Seams. Django-admin-ext 0.1.6. Working with models, part 2. Now that we’ve got a handle on how to generically load models without necessarily knowing in advance which models, it’s time to start looking at interesting things we can do with them once we’ve got them.
There are lots of uses for code which can introspect any model and extract information from it, some of which you’ve probably already seen: The Django admin interface introspects model classes to determine how to display and edit them. Shortcuts in both the old and new forms systems exist for generating forms automatically from a model (AddManipulator and ChangeManipulator in oldforms, form_for_model and form_for_instance in newforms). Django’s serialization system can transform a QuerySet into JSON or XML, and back again into objects in your database.
So how can your code do the same sorts of things? A small warning You got _meta all over my model! One of the more important bits of information you can get out of _meta is a list of the model’s fields; for example: Forms and validation. When you can't return a response object, throw it. Django documentation. Django CMS: copying a complete page tree to a new site. Within Django you can use a manager to execute frequently used database queries. Within you self-written apps it's just a matter of defining the manager in the model. But in some projects you just want to make a add a few queries within a existing package. Yeah sure, I could redeclare a model and add my manager to it. But that mostly requires additional development to make sure the model and manager continue to work properly. And what if I want to add just 1 additional query command to the User Manager within the Django user authentication system? I have to write a custom authentication back-end to communicate with my customer User model.
So let's say I regularly want to perform a query to retrieve all active Django users. From django.db import models class CustomUserManager(models.Manager): def get_active_users(self): return self.get_query_set().filter(is_active=True) Now we have to tell our User model there's a new manager. Editing multiple objects in Django with forms | Collin Grady. February 18, 2008 at 1:45 pm | Posted in django | 6 Comments A common problem I see when helping people in the Django IRC channel is people who are trying to create or edit multiple objects, but for some reason try to make a single form object to deal with them – this makes things quite convoluted and much harder than they have to be.
My goal here is to explain a much simpler method using multiple form objects. For this guide, I’m going to use the basic Poll and Choice models from the tutorial. I’m only showing the fields here, as that’s all that matters to the form, but they wouldn’t break anything, of course :) from django.db import models class Poll(models.Model): question = models.CharField(max_length=200) pub_date = models.DateTimeField() class Choice(models.Model): poll = models.ForeignKey(Poll) choice = models.CharField(max_length=200) votes = models.IntegerField(default=0) To start, we’ll need forms for each model.
There may be other methods, but this should work fine :) Like this: Creating forms from models. ModelForm class ModelForm If you’re building a database-driven app, chances are you’ll have forms that map closely to Django models. For instance, you might have a BlogComment model, and you want to create a form that lets people submit comments. In this case, it would be redundant to define the field types in your form, because you’ve already defined the fields in your model. For this reason, Django provides a helper class that lets you create a Form class from a Django model. For example: >>> from django.forms import ModelForm>>> from myapp.models import Article # Create the form class.
>>> class ArticleForm(ModelForm):... class Meta:... model = Article... fields = ['pub_date', 'headline', 'content', 'reporter'] # Creating a form to add an article. >>> form = ArticleForm() # Creating a form to change an existing article. >>> article = Article.objects.get(pk=1)>>> form = ArticleForm(instance=article) Field types Each model field has a corresponding default form field. A full example Warning Note. Selectors Level 3. Abstract Selectors are patterns that match against elements in a tree, and as such form one of several technologies that can be used to select nodes in an XML document. Selectors have been optimized for use with HTML and XML, and are designed to be usable in performance-critical code.
CSS (Cascading Style Sheets) is a language for describing the rendering of HTML and XML documents on screen, on paper, in speech, etc. CSS uses Selectors for binding style properties to elements in the document. This document describes the selectors that already exist in CSS1 [CSS1] and CSS2 [CSS21], and further introduces new selectors for CSS3 and other languages that may need them. Selectors define the following function: expression ∗ element → boolean That is, given an element and a selector, this specification defines whether that element matches the selector. Status of this document This section describes the status of this document at the time of its publication. Table of Contents 1. 1.1. 1.2. 1.3. 2. 3. .
Encrypting Database Data in Django | Tyler Lesmann. This last week I was putting together a password management application for our group at work. The biggest obstacle was adding encryption to the password data in the database. At first I thought, "I'll use Django's password field. " Django uses one-way hashes like all good authentication systems though. I solved this by making my own custom field, extended from django's CharField. The first step was learning how to do cryptography in python.
I found PyCrypto. I does both ciphers and hashes in various algorithms. AES has a few requirements. If you execute this, it will generate a key and a string, plus encrypt and decrypt the string. If you run this, you'll see a line like, Encrypted base64: vF7nMm7N1EhalQ/4gtQhaxEHeCgY2dOsNf2rA7tQZW8=. All that's left now is our custom field. This requires the user to have a AESKEY set in the settings.py of their project. Set Up Python and Install Django on Mac OS X Lion 10.7 | Hacker Codex. NOTE: This guide was written for Lion 10.7 and has since been superceded by these new guides: First steps Lion has done away with the “Sites” folder by default, but it’s easy to add it back — the custom icon will even show up automatically.
Use the Finder, or enter the following in a Terminal session: Another change is the hidden ~/Library folder. We can make it visible again with the following command (which gets overridden by OS updates and must be run again afterwards): chflags nohidden ~/Library/ Since Lion is a full 64-bit system, we’ll save some headaches by letting our compiler know that all compilation should assume 64 bits.
. … and add: # Set architecture flagsexport ARCHFLAGS="-arch x86_64" With those first steps out of the way, now it’s time to get the necessary compilation tools in place. Compiler Installing development-related software in the past has required the compiler tool-chain that comes with Xcode. Homebrew That’s it — Homebrew is now installed. Python site-packages Dotfiles. Deschler/django-modeltranslation.
Easymode : toolkit for making xml based flash websites — django-easymode v1.0b1 documentation. With easymode you can create backends for dynamic flash/flex websites. Easymode makes internationalization simple and outputs xml by default. To tailor the xml to your application, you can transform it using xslt templates, which easymode integrates. For more info, look at Why does easymode exist? The best way to learn how easymode works, is to read the above topics in sequence and then look at the example_app. If you have questions please send them to the mailing list at easymode@librelist.com.
Easymode requires python 2.6, furthermore the following packages must be installed: Django The following packages might also be required, depending on what features you are using. lxmlpolibdjango-reversion Easymode comes with an example app which is available from github: To run the example app, you must clone the repository, install the dependencies and initialize the database: Each update to the development status will increase the first digit. Starting a Django 1.4 Project the Right Way. Check out the new, updated version of this post with Django 1.6 specific changes and updates. Back in February, I wrote a post titled 'Starting a Django Project the Right Way', which still draws a consistent audience eight months later.
In those eight months, Django has released version 1.4 of the framework, with 1.5 under active development and promising experimental support for Python 3.x. Given these changes, as well as the availability of new and updated resources available to Django developers, I decided to revisit the concept of best practices when starting a Django project. The beginning of a project is a critical time. By the end of this post, you will have None of these steps, except for perhaps the first, are covered in the official tutorial. Prerequisites A working knowledge of Python is assumed. Preparing To Install I'm assuming you have Python installed. So, what's the first step? $ pip install virtualenvwrapper Creating a new environment $ mkvirtualenv django_project git Mercurial. Pinax.