<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-1148195454380051662</id><updated>2012-01-23T18:39:35.731-08:00</updated><category term='voting'/><category term='queryset'/><category term='extending'/><category term='managers'/><category term='table'/><category term='sport'/><category term='mysql'/><category term='boycote'/><category term='admin'/><category term='dummynet'/><category term='ipfw'/><category term='kungfu'/><category term='programming'/><category term='newforms'/><category term='taichi'/><category term='models'/><category term='sorting'/><category term='ymaa'/><category term='qos'/><category term='gdynia'/><category term='django'/><category term='user'/><category term='chrome'/><category term='pagination'/><category term='authinfo'/><category term='firefox'/><category term='adblock'/><category term='domeny'/><category term='monopoly'/><category term='python'/><category term='unix'/><category term='jail'/><category term='freebsd'/><category term='firewall'/><category term='comments'/><category term='google'/><category term='web browsers'/><category term='vps'/><title type='text'>Robert's blog</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>13</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-6248312407982444715</id><published>2009-07-05T14:39:00.000-07:00</published><updated>2011-12-14T14:03:42.464-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='sorting'/><category scheme='http://www.blogger.com/atom/ns#' term='queryset'/><title type='text'>django-sorting a generic way of queryset sorting</title><content type='html'>&lt;br /&gt;Just found a great project django-sorting. It's a generic way of queryset sorting.&lt;br /&gt;It's based on middleware, and templatetag.&lt;br /&gt;&lt;br /&gt;Please read the README.txt of the project.&lt;br /&gt;&lt;br /&gt;In couple easy steps you get sorting:&lt;br /&gt;&lt;br /&gt;1. Download &amp;amp; install django-sorting&lt;br /&gt;2.In your settings.py&lt;br /&gt;- add 'django-sorting' to INSTALLED_APPS&lt;br /&gt;- add 'django_sorting.middleware.SortingMiddleware' to MIDDLEWARE_CLASSES&lt;br /&gt;(make sure 'django.core.context_processors.request' is in your TEMPLATE_CONTEXT_PROCESSORS&lt;br /&gt;3. In your template code: (the one below goes directly from README.txt&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;pre class='brush: html'&gt;&lt;br /&gt;{% anchor first_name "First Name" %}&lt;br /&gt;&lt;br /&gt;{% anchor last_name "Last Name" %}&lt;br /&gt;&lt;br /&gt;{% anchor creation_date Creation flojax my_container %}&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first argument is a field of the objects list, and the second&lt;br /&gt;&lt;br /&gt;one(optional) is a title that would be displayed. The previous&lt;br /&gt;&lt;br /&gt;snippet will be rendered like this:&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;...&lt;br /&gt;First Name&lt;br /&gt;Last Name&lt;br /&gt;Creation&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;It's BRILLIANT!&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You should also use django-pagination for pagination support written by Eric as well.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Thank you ERIC!&lt;br /&gt;&lt;br /&gt;Ps. Big thanks go to Karim (first author of django-sorting code) and other contributtors of these 2 great projects.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-6248312407982444715?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/6248312407982444715/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=6248312407982444715' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6248312407982444715'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6248312407982444715'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2009/07/django-sorting-generic-way-of-queryset.html' title='django-sorting a generic way of queryset sorting'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-6111189432769734461</id><published>2009-01-26T05:30:00.000-08:00</published><updated>2009-01-26T06:17:37.258-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='admin'/><category scheme='http://www.blogger.com/atom/ns#' term='authinfo'/><category scheme='http://www.blogger.com/atom/ns#' term='domeny'/><title type='text'>[PL] Authinfo i transfer domeny</title><content type='html'>Postanowiłem przenieść swoje domeny *.pl do innego registrara.&lt;br /&gt;&lt;br /&gt;Jak wszyscy wiemy, niedawno NASK obniżył opłaty za przedłużenie domen, &lt;br /&gt;która w przypadku domen *.pl wynosi 40 PLN netto. Obniżka cen miała miejsce niedawno.&lt;br /&gt;Mowa o obniżce cen dla partnerów. Zwykły zjadacz domen dalej płaci 200 PLN netto, a raczej 244 pln brutto.&lt;br /&gt;&lt;br /&gt;Jak można się domyśleć, nie przełożyło się to na obniżki cen domen u popularnych u nas firm rejestrujących domeny, jak home.pl itd - cena 99 pln netto (stan na 26.01.2009).&lt;br /&gt;&lt;br /&gt;Wiadomo, każdy chce zarabiać.&lt;br /&gt;&lt;br /&gt;Wcześniej transferowałem domenę *.com z firmy godaddy. Tam w 10 sekund, po wybraniu opcji "wyślij kod authinfo" otrzymałem emailem kod. Proste i przyjemne.&lt;br /&gt;&lt;br /&gt;Niestety nie w Polsce.&lt;br /&gt;Pierw wypełnienie formularza, wpisanie telefonu i powodu, dla którego chcemy authinfo. Można się domyśleć - bo chcę dokonać transferu (nie kłamałem, wpisałem).&lt;br /&gt;&lt;br /&gt;Otrzymałem po 2 dniach emaila, z propozycją obniżenia opłaty za przedłużenie ze 100 do 80 pln netto. W emailu załączony był również wniosek. Wypełniłem, podpieczętowałem, przefaxowałem.&lt;br /&gt;&lt;br /&gt;Następnie dostałem emailem info, że wniosek przyjęty i że mam zalogować się znowu do innej strony (podano mi login/hasło). Tam się zalogowałem i znowu kolejne 2 wnioski do wypełniania, podpisania, podpieczętowania i przefaxowania wraz dokumentami: NIP, regon, wpis do ewidencji.&lt;br /&gt;&lt;br /&gt;Uwaga: wniosek dotyczy tylko jednej z dwóch domen *.pl&lt;br /&gt;Do jednej dostałem już kod authinfo! Widocznie chcą mocnych dowodów, że ja to ja.&lt;br /&gt;&lt;br /&gt;Szkoda tylko papieru, drzew. Zarabia na tym chociaż operator telekomunikacyjny,&lt;br /&gt;bo faxy wysyłać trzeba.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-6111189432769734461?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/6111189432769734461/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=6111189432769734461' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6111189432769734461'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6111189432769734461'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2009/01/pl-authinfo-i-transfer-domeny.html' title='[PL] Authinfo i transfer domeny'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-5250207687700046495</id><published>2009-01-13T07:02:00.000-08:00</published><updated>2009-01-13T07:08:58.465-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gdynia'/><category scheme='http://www.blogger.com/atom/ns#' term='ymaa'/><category scheme='http://www.blogger.com/atom/ns#' term='taichi'/><category scheme='http://www.blogger.com/atom/ns#' term='sport'/><category scheme='http://www.blogger.com/atom/ns#' term='kungfu'/><title type='text'>Ćwicz po pracy!</title><content type='html'>Uważam, że człowiek może dostać kręćka od monotonnego trybu życia, w skład którego wchodziłyby tylko praca i sen.&lt;br /&gt;&lt;br /&gt;Zachęcam każdego gorąco do aktywności ruchowej minimum 2 razy w tygodniu.&lt;br /&gt;Gorąco polecam basen, piłkę nożną oraz sztuki walki :)&lt;br /&gt;&lt;br /&gt;Dla mieszkających w okolicy Gdyni polecić mogę &lt;a href="http://ymaa.gdynia.pl"&gt;gdyńską szkołę TaiChi, oraz KungFu (a także Qigong) - YMAA GDYNIA.&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Treningi odbywają się w poniedziałki oraz środy.&lt;br /&gt;W pozostałe dni polecam basen :)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-5250207687700046495?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/5250207687700046495/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=5250207687700046495' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/5250207687700046495'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/5250207687700046495'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2009/01/wicz-po-pracy.html' title='Ćwicz po pracy!'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-2129071093812809046</id><published>2008-10-16T11:17:00.000-07:00</published><updated>2008-10-16T11:23:08.452-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='firefox'/><category scheme='http://www.blogger.com/atom/ns#' term='boycote'/><category scheme='http://www.blogger.com/atom/ns#' term='web browsers'/><category scheme='http://www.blogger.com/atom/ns#' term='chrome'/><category scheme='http://www.blogger.com/atom/ns#' term='google'/><category scheme='http://www.blogger.com/atom/ns#' term='adblock'/><title type='text'>SAY NO TO FLASH POPUPS!</title><content type='html'>I've been a Firefox user for a long time.&lt;br /&gt;&lt;br /&gt;After Google Chrome has been published I decided to check it out.&lt;br /&gt;After 1 day I had to switch back to Firefox.&lt;br /&gt;&lt;br /&gt;The reason?&lt;br /&gt;&lt;a href="https://addons.mozilla.org/firefox/addon/10"&gt;https://addons.mozilla.org/firefox/addon/10&lt;/a&gt; (Firefox AdBlock plugin)&lt;br /&gt;&lt;br /&gt;It's IMPOSSIBLE to watch the web without this plugin.&lt;br /&gt;Flash plugins everywhere ... This is horrible.&lt;br /&gt;&lt;br /&gt;People! Use this plugin, do not let manipulate and waste your time on&lt;br /&gt;pages using this harmful type of advertising.&lt;br /&gt;&lt;br /&gt;Boycote it! Let others know to not use it!&lt;br /&gt;Admins, block ad hosts too!&lt;br /&gt;&lt;br /&gt;I do not mean to fight with ads. I can watch ads, as long as it does not eat 100% of my CPU and some fuckin* flash poup appears! AARGH!!&lt;br /&gt;&lt;br /&gt;THIS IS CRAZY!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-2129071093812809046?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/2129071093812809046/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=2129071093812809046' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/2129071093812809046'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/2129071093812809046'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/10/say-no-to-flash-popups.html' title='SAY NO TO FLASH POPUPS!'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-3840803487809782634</id><published>2008-10-09T05:21:00.001-07:00</published><updated>2011-12-14T13:59:29.478-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='pagination'/><category scheme='http://www.blogger.com/atom/ns#' term='sorting'/><category scheme='http://www.blogger.com/atom/ns#' term='table'/><category scheme='http://www.blogger.com/atom/ns#' term='queryset'/><title type='text'>django-tables generic way for displaying tables (pagination included)</title><content type='html'>&lt;blockquote class="tr_bq"&gt;In thnis short post I would like to let you know about the great project&lt;/blockquote&gt;&lt;a href="https://launchpad.net/django-tables"&gt;django-tables&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;You can read more about it at:&lt;br /&gt;&lt;a href="http://blog.elsdoerfer.name/2008/07/09/django-tables-a-queryset-renderer/"&gt;http://blog.elsdoerfer.name/2008/07/09/django-tables-a-queryset-renderer/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;In a couple of words it lets you:&lt;br /&gt;- display the table using one template which lets you sort &amp;amp; paginate easily (filtering in plans!)&lt;br /&gt;&lt;br /&gt;By reading the text below you will find out how to create table with sort &amp;amp; pagination quickly.&lt;br /&gt;&lt;br /&gt;In usage it's very similar do django newforms (forms as of 1.0)&lt;br /&gt;Example: (views.py)&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: python"&gt;class MyTable(tables.ModelTable):&lt;br /&gt;&lt;br /&gt;  class Meta:&lt;br /&gt;      model = SomeModel&lt;br /&gt;&lt;br /&gt;def view_something(request):&lt;br /&gt;  table = MyTable(queryset, order_by=request.GET.get('sort','some_field))&lt;br /&gt;&lt;br /&gt;  return render_to_response('templates/table.html', {'table': table, 'rows' : table.rows})&lt;br /&gt;# we need to return table, and  rows separately to use &lt;a href="http://code.google.com/p/django-pagination/"&gt;django-paginatio&lt;/a&gt;n (though django-tables provides its own pagination mechanism)&lt;/pre&gt;&lt;br /&gt;Now let's get to template:&lt;br /&gt;&lt;br /&gt;&lt;pre class="brush: html"&gt;{% load pagination_tags %}&lt;br /&gt;{% autopaginate rows 10 %}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;  {% for column in table.columns %}&lt;br /&gt;&lt;br /&gt;  {% endfor %}&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;{% for row in rows %}&lt;br /&gt;&lt;br /&gt;  {% for value in row %}&lt;br /&gt;&lt;br /&gt;{% endfor %}&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;tbody&gt;&lt;br /&gt;&lt;tr&gt;  &lt;th&gt;&lt;br /&gt;&lt;br /&gt;{% if column.sortable %}&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.blogger.com/blogger.g?sort={{%20column.name_toggled%20}}"&gt;&lt;br /&gt;        {{ column }}&lt;br /&gt;      &lt;/a&gt;&lt;br /&gt;&lt;br /&gt;{% if column.is_ordered_reverse %}&lt;br /&gt;&lt;br /&gt;&lt;img src="up.png" /&gt;&lt;br /&gt;&lt;br /&gt;{% else %}&lt;br /&gt;&lt;br /&gt;&lt;img src="down.png" /&gt;&lt;br /&gt;&lt;br /&gt;{% endif %}&lt;br /&gt;&lt;br /&gt;{% else %}&lt;br /&gt;&lt;br /&gt;{{ column }}&lt;br /&gt;&lt;br /&gt;{% endif %}&lt;/th&gt;&lt;/tr&gt;&lt;br /&gt;&lt;tr&gt;    &lt;td&gt;{{ value }}&lt;/td&gt;&lt;td&gt;&lt;br /&gt;&lt;br /&gt;{% endfor %}&lt;/td&gt;&lt;/tr&gt;&lt;br /&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;br /&gt;{% paginate %}&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;That's it!&lt;br /&gt;&lt;br /&gt;This way you get generic way of displaying tables + sorting ability.&lt;br /&gt;By default, django-tables takes field names for table headers when using ModelTable (verbose_name is in plans as well).&lt;br /&gt;You can exclude displaying fields too!&lt;br /&gt;&lt;br /&gt;As for now, you can specify your own names in MyTable class.&lt;br /&gt;&lt;br /&gt;Let's get back to our class:&lt;br /&gt;&lt;br /&gt;&lt;pre class='brush: python'&gt;class MyTable(tables.ModelTable):&lt;br /&gt;  class Meta:&lt;br /&gt;      model = SomeModel&lt;br /&gt;&lt;br /&gt;  field1 = tables.Column(name="Name")&lt;br /&gt;  field_we_want_to_exclude = tables.Column(visiable=Fale, sortable=False)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;NOTE:&lt;br /&gt;Django tables is also aware of ForeignKey relations.&lt;br /&gt;&lt;br /&gt;Check it out!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-3840803487809782634?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/3840803487809782634/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=3840803487809782634' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/3840803487809782634'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/3840803487809782634'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/10/django-tables-generic-way-for.html' title='django-tables generic way for displaying tables (pagination included)'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-6470593869298885521</id><published>2008-03-03T11:09:00.001-08:00</published><updated>2008-10-09T06:40:29.864-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='newforms'/><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><title type='text'>Django ModelForm - replacement for form_for_model &amp; form_for_instance</title><content type='html'>Each commit, &lt;a href="http://www.djangoproject.com"&gt;Django&lt;/a&gt; gets more amazing.&lt;br /&gt;&lt;br /&gt;I wrote about &lt;a href="http://www.djangoproject.com/documentation/newforms/"&gt;newforms&lt;/a&gt; library before. The library was a big step in Django form displaying and validating.&lt;br /&gt;&lt;br /&gt;The first approach was to use &lt;a href="http://www.djangoproject.com/documentation/form_for_model/"&gt;forms.form_for_model()&lt;/a&gt; and forms.form_for_instance() respectively.&lt;br /&gt;&lt;br /&gt;As Django programmer I found this a little confusing. Both were similar. The only difference was that form_for_instance() took an object instance for saving instead&lt;br /&gt; of creating a new one. Recently django developers came up with a great idea - &lt;a href="http://www.djangoproject.com/documentation/modelforms/"&gt;forms.ModelForm&lt;/a&gt; which combines both into one. It's great!&lt;br /&gt;&lt;br /&gt;Just take a look at the example below.&lt;br /&gt;Assume you want to create a new view function for creating &amp; editing an object.&lt;br /&gt;You only want to edit 3 fields (name, last_name, status). Also, you've created a &lt;br /&gt;customized field type for "status", and want to use that.&lt;br /&gt;&lt;br /&gt;Scenario #1: (forms.form_for_model &amp;&amp; forms.form_for_instance)&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;def f_callback(field, **kwargs):&lt;br /&gt;    if field.name == "status":&lt;br /&gt;        return MyStatusField(**kwargs)&lt;br /&gt;    else:&lt;br /&gt;        return field.formfield(**kwargs)&lt;br /&gt;&lt;br /&gt;def create_edit_customer(request, customer_id=None):&lt;br /&gt;&lt;br /&gt;    # check if object_id is None and if object exists&lt;br /&gt;    if object_id is None:&lt;br /&gt;        CustomerForm = forms.form_for_model(Customer,&lt;br /&gt;        formfield_callback=f_callback,&lt;br /&gt;        fields=('name','last_name','status')&lt;br /&gt;    else:&lt;br /&gt;        customer = get_object_or_404(Customer, id=customer_id)&lt;br /&gt;        CustomerForm = forms.form_for_instance(customer,&lt;br /&gt;        formfield_callback=f_callback,&lt;br /&gt;        fields=('name','last_name','status')&lt;br /&gt;&lt;br /&gt;    if request.method == "POST":&lt;br /&gt;        form = CustomerForm(request.POST)&lt;br /&gt;        if form.is_valid():&lt;br /&gt;            form.save()&lt;br /&gt;            return HttpResponseRedirect('customer/added/')&lt;br /&gt;    else:&lt;br /&gt;        form = CustomerForm()&lt;br /&gt;&lt;br /&gt;    return render_to_response("customers/customer_form.html", {'form' : form })&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You could create your own form_for_model &amp; form_for_instance subclass (using forms.BaseForm for example), but it would be too complicated. Hope you don't use this form often :-)&lt;br /&gt;&lt;br /&gt;Scenario #2 (ModelForm)&lt;br /&gt;&lt;br /&gt;1. Longer version.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;class CustomerModelForm(forms.ModelForm):&lt;br /&gt;&lt;br /&gt;    class Meta:&lt;br /&gt;        model = Customer&lt;br /&gt;        fields = ('name','last_name','status')&lt;br /&gt;&lt;br /&gt;        status = MyCustomerField()&lt;br /&gt;&lt;br /&gt;def create_edit_customer(request, customer_id=None):&lt;br /&gt;&lt;br /&gt;    if customer_id is not None:&lt;br /&gt;        customer = get_object_or_404(Customer, id=customer_id)&lt;br /&gt;    else:&lt;br /&gt;        customer = None&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;    if request.method == "POST":&lt;br /&gt;        form = CustomerModelForm(data=request.POST, instance=customer)&lt;br /&gt;        if form.is_valid():&lt;br /&gt;            form.save()&lt;br /&gt;            return HttpResponseRedirect("/customer/added/")&lt;br /&gt;        else:&lt;br /&gt;            form = CustomerModelForm(instance=customer)&lt;br /&gt;&lt;br /&gt;    return render_to_response("customers/customer_form.html", {'form' : form })&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;2. Shorter version.&lt;br /&gt;&lt;br /&gt;&lt;pre name="code" class="python"&gt;&lt;br /&gt;class CustomerModelForm(forms.ModelForm):&lt;br /&gt;&lt;br /&gt;    class Meta:&lt;br /&gt;        model = Customer&lt;br /&gt;        fields = ('name','last_name','status')&lt;br /&gt;&lt;br /&gt;    status = MyCustomerField()&lt;br /&gt;&lt;br /&gt;def create_edit_customer(request, customer_id=None):&lt;br /&gt;&lt;br /&gt;    if customer_id is not None:&lt;br /&gt;        customer = get_object_or_404(Customer, id=customer_id)&lt;br /&gt;    else:&lt;br /&gt;        customer = None&lt;br /&gt;&lt;br /&gt;    form = CustomerModelForm(data=request.POST or None, instance=customer)&lt;br /&gt;&lt;br /&gt;    if form.is_valid():&lt;br /&gt;        form.save()&lt;br /&gt;        return HttpResponseRedirect("/customer/added/")&lt;br /&gt;&lt;br /&gt;    return render_to_response("customers/customer_form.html", {'form' : form }&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;We are using one form class for editing &amp; creating objects.&lt;br /&gt;We can also subclass CustomerModelForm and edit/change the way the form looks&lt;br /&gt;and behave (by adding field clean() method.&lt;br /&gt;&lt;br /&gt;Django forms library looks better each day :-)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-6470593869298885521?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/6470593869298885521/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=6470593869298885521' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6470593869298885521'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6470593869298885521'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/03/django-modelform-replacement-for.html' title='Django ModelForm - replacement for form_for_model &amp; form_for_instance'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-6524185710415524996</id><published>2008-03-02T07:27:00.001-08:00</published><updated>2008-03-02T07:31:55.662-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='gdynia'/><category scheme='http://www.blogger.com/atom/ns#' term='monopoly'/><title type='text'>Vote for Gdynia in Monopoly Game</title><content type='html'>I was born in Gdynia, I grew up in Gdynia.. and I am happy to live in Gdynia.&lt;br /&gt;&lt;br /&gt;Now it's chance for anybody to vote for Gdynia in the Worldwide Monopoly&lt;br /&gt;city competition.&lt;br /&gt;&lt;br /&gt;Log in at: &lt;br /&gt;http://www.monopolyworldvote.com/pl_PL/world and vote.&lt;br /&gt;You can give your vote once a day.&lt;br /&gt;&lt;br /&gt;Thanks!&lt;br /&gt;&lt;br /&gt;---&lt;br /&gt;Urodziłem się w Gdyni, dorastałem w Gdyni i nadal mieszkam w Gdyni.&lt;br /&gt;To cudowne miasto ma teraz niepowtarzalną okazję zaistnieć w &lt;br /&gt;ogólnoświatowej wersji gry Monopol, w którą grają miliony&lt;br /&gt;ludzi na świecie. &lt;br /&gt;To niepowtarzalna szansa dla promocji naszego miasta, ale też i kraju,&lt;br /&gt;czy też rejonu.&lt;br /&gt;&lt;br /&gt;Oddaj swój głos na stronie:&lt;br /&gt;http://www.monopolyworldvote.com/pl_PL/world&lt;br /&gt;&lt;br /&gt;Możesz głosować codziennie 1 raz!&lt;br /&gt;&lt;br /&gt;Dzięki !&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-6524185710415524996?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/6524185710415524996/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=6524185710415524996' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6524185710415524996'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6524185710415524996'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/03/vote-for-gdynia-in-monopoly-game.html' title='Vote for Gdynia in Monopoly Game'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-1529633360559197225</id><published>2008-02-29T10:32:00.000-08:00</published><updated>2008-02-29T10:47:31.253-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='freebsd'/><category scheme='http://www.blogger.com/atom/ns#' term='mysql'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><title type='text'>FreeBSD 7.0 arrived</title><content type='html'>FreeBSD 7.0 offers new great features. You can read about them all &lt;a href="http://www.freebsd.org/releases/7.0R/relnotes.html"&gt;here&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;With this release we can see a huge performance&lt;br /&gt;improvements. Just take a look at these MySQL tests! It looks very promising.&lt;br /&gt;&lt;br /&gt;It would be great if ULE scheduler was stable enough to be included in 7.1 release.&lt;br /&gt;&lt;br /&gt;During my work at the company where MySQL was widely used, I had to use linuxthreads&lt;br /&gt;package to get similar to linux performance (well, that's because we used FreeBSD 4.X then). Linux (mostly 2.6) is treated as a better&lt;br /&gt;Operating system for MySQL. Is it high time to change it? :-). Go FreeBSD!&lt;br /&gt;&lt;br /&gt;Take a look at graphs at:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://people.freebsd.org/~kris/scaling/mysql.html"&gt;http://people.freebsd.org/~kris/scaling/mysql.html&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-1529633360559197225?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/1529633360559197225/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=1529633360559197225' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/1529633360559197225'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/1529633360559197225'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/02/freebsd-70-arrived.html' title='FreeBSD 7.0 arrived'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-7139304184359362128</id><published>2008-02-25T06:30:00.000-08:00</published><updated>2008-02-25T06:39:29.725-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='comments'/><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='programming'/><category scheme='http://www.blogger.com/atom/ns#' term='voting'/><title type='text'>Some very usable django apps</title><content type='html'>I was looking for some easy to plug-in django apps&lt;br /&gt;for my new service.&lt;br /&gt;&lt;br /&gt;Here are some I decided to use:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/django-tagging/"&gt;django-tagging&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/django-registration/ "&gt;django-registration&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/django-threadedcomments"&gt;django-threadedcomments&lt;/a&gt;&lt;br /&gt;&lt;a href="http://code.google.com/p/django-voting/"&gt;django-voting&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;They seem to be rock stable, and easy to use.&lt;br /&gt;&lt;br /&gt;Check back soon for more info about the new website.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-7139304184359362128?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/7139304184359362128/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=7139304184359362128' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/7139304184359362128'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/7139304184359362128'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2008/02/some-very-usable-django-apps.html' title='Some very usable django apps'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-8893139915327363723</id><published>2007-06-15T03:10:00.000-07:00</published><updated>2007-06-15T06:27:28.324-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='admin'/><category scheme='http://www.blogger.com/atom/ns#' term='freebsd'/><category scheme='http://www.blogger.com/atom/ns#' term='firewall'/><category scheme='http://www.blogger.com/atom/ns#' term='ipfw'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='qos'/><category scheme='http://www.blogger.com/atom/ns#' term='dummynet'/><title type='text'>[EN] FreeBSD QOS with FreeBSD DUMMYNET</title><content type='html'>The latest released FreeBSD version 6.2  comes with 3 firewall systems:&lt;br /&gt;&lt;br /&gt;- pf (ported from OpenBSD)&lt;br /&gt;- ipfw&lt;br /&gt;- ipfilter&lt;br /&gt;&lt;br /&gt;All these three are stable as of this release. I've recently needed to run a QOS system, and chosen&lt;br /&gt;ipfw "DUMMYNET" for this purpose.&lt;br /&gt;&lt;br /&gt;My network is about couple hundreds computers and I needed limit bandwidth for each user.&lt;br /&gt;&lt;br /&gt;I chose DUMMYNET because of it's simplicity, and "dynamic pipe" creation. I know "pf" (especially HFSC alghoritm) is a good solution too, but natively it supports up to 64 queues&lt;br /&gt;per interface, and you need to patch the source in order to enable more. It's safe to use hundreds of queues, but I simply don't like patching.. (at least by now).&lt;br /&gt;&lt;br /&gt;DUMMYNET provides FreeBSD users with dynamic pipe creation.&lt;br /&gt;&lt;br /&gt;Suppose you want to create a new 256Kbit pipe for incoming, and 128Kbit pipe for outgoing traffic.&lt;br /&gt;&lt;br /&gt;# ipfw pipe 1 config bw 256Kbit/s mask dst-addr 0xffffffff&lt;br /&gt;# ipfw pipe 1 config bw 128Kbit/s mask src-addr 0xffffffff&lt;br /&gt;&lt;br /&gt;Now, you need to put the traffic into these pipes.&lt;br /&gt;&lt;br /&gt;# ipfw add pipe 1 ip from any to 192.168.0.0/24, 192.168.1.0/24&lt;br /&gt;# ipfw add pipe 2 ip from 192.168.0.0/24, 192.168.1.0/24 to any&lt;br /&gt;&lt;br /&gt;By these 4 lines of code you will get hunderds of pipes for each ip in the network for&lt;br /&gt;both incoming and outgoing traffic.&lt;br /&gt;&lt;br /&gt;You could write it this way as well:&lt;br /&gt;&lt;br /&gt;# ipfw pipe 1 config bw 256Kbit/s&lt;br /&gt;# ipfw pipe 2 config bw 256Kbit/s&lt;br /&gt;...&lt;br /&gt;# ipfw pipe 345 config bw 256Kbit/s&lt;br /&gt;&lt;br /&gt;and appropriate rules:&lt;br /&gt;# ipfw add pipe 1 ip from any to 192.168.0.2&lt;br /&gt;# ipfw add pipe 2 ip from any to 192.168.0.3&lt;br /&gt;....&lt;br /&gt;# ipfw add pipe 345 ip from any t0 192.168.1.23&lt;br /&gt;&lt;br /&gt;I think the first solution is better!&lt;br /&gt;&lt;br /&gt;Now that we stand with another problem - some users have more bandwidth enabled, some less.&lt;br /&gt;&lt;br /&gt;You could write pipes with mask-src (dynamic), and put hosts into these.. which would cause lots of rules written.&lt;br /&gt;&lt;br /&gt;ipfw (ipfw2 for FreeBSD 4.X) comes with lookup tables, which are extremely fast!&lt;br /&gt;&lt;br /&gt;There are 2 values stored in each record of the table:&lt;br /&gt;ip address or network, integer&lt;br /&gt;&lt;br /&gt;To create a new table and put the record you would:&lt;br /&gt;&lt;br /&gt;# ipfw table 1 add 192.168.0.2 23&lt;br /&gt;# ipfw table 1 add 192.168.0.3,345&lt;br /&gt;&lt;br /&gt;These 2nd values lets filter by these in the rules.&lt;br /&gt;&lt;br /&gt;# ipfw add allow ip from table\(1\,23) to any # ( = ipfw add allow ip from 192.168.0.2 to any)&lt;br /&gt;&lt;br /&gt;Now, in order to create more complex ruleset for pipe assigning look at the example below:&lt;br /&gt;&lt;br /&gt;# incoming traffic&lt;br /&gt;# ipfw pipe 1 config bw 1024Kbit/s mask dst-addr 0xffffffff&lt;br /&gt;# ipfw pipe 2 config bw 512Kbit/s mask dst-addr 0xffffffff&lt;br /&gt;# ipfw pipe 3 config bw 256Kbit/s mask dst-addr 0xffffffff&lt;br /&gt;&lt;br /&gt;# outgoing traffic&lt;br /&gt;# ipfw pipe 11 config bw 1024Kbit/s mask src-addr 0xffffffff&lt;br /&gt;# ipfw pipe 12 config bw 512Kbit/s mask src-addr 0xffffffff&lt;br /&gt;# ipfw pipe 13 config bw 256Kbit/s mask src-addr 0xffffffff&lt;br /&gt;&lt;br /&gt;# Create 2 lookup tables, one with values (IP,INCOMING_BANDWIDTH), second with (IP, OUTGOING_BANDWIDTH)&lt;br /&gt;# TABLE 1 (incoming)&lt;br /&gt;# ipfw table 1 add 192.168.0.2 1024&lt;br /&gt;# ipfw table 1 add 192.168.0.3 1024&lt;br /&gt;# ipfw table 1 add 192.168.1.0/24 512 # each host in network 192.168.1.0/24 gets 512 Kbit/s)&lt;br /&gt;....&lt;br /&gt;# ipfw table 1 add 192.168.2.23 256&lt;br /&gt;&lt;br /&gt;# TABLE 2 (outgoing)&lt;br /&gt;# ipfw table 2 add 192.168.0.2 512&lt;br /&gt;# ipfw table 2 add 192.168.0.3 512&lt;br /&gt;# ipfw table 2 add 192.168.1.0/24 256 # yeah, network 192.168.1.0 got too much traffic last month, now they will get less&lt;br /&gt;&lt;br /&gt;# RULES&lt;br /&gt;# rule for incoming pipe 1024kbit (pipe #1)&lt;br /&gt;# ipfw add pipe 1 ip from any to table\(1,1024\)&lt;br /&gt;# rule for incoming pipe 512 (pipe #2)&lt;br /&gt;# ipfw add pipe 2 ip from any to table\(1,512\)&lt;br /&gt;# rule for incoming pipe 256 (pipe #3)&lt;br /&gt;# ipfw add pipe 3 ip from any to table\(1,256\)&lt;br /&gt;&lt;br /&gt;# outgoing traffic&lt;br /&gt;# fule for outgoing pipe 1024Kbit (pipe #11)&lt;br /&gt;# ipw add pipe 11 ip from table\(2,1024\) to any&lt;br /&gt;# rule for outgoing pipe 512Kbit (pipe #12)&lt;br /&gt;# ipfw add pipe 12 ip from table\(2,512\) to any&lt;br /&gt;# rule for outgoing pipe 256Kbit (pipe #13)&lt;br /&gt;# ipfw add pipe 13 ip from table\(2,256\) to any&lt;br /&gt;&lt;br /&gt;That's all! No more hundreds of static pipes, hundreds of rules.&lt;br /&gt;&lt;br /&gt;Keep in mind, that this example is a strcitly pipe related.&lt;br /&gt;Depending on the NAT you are using, make sure these rules are evaluated&lt;br /&gt;before being nated (if using "natd") for outgoing traffic, and after being nated (if using "natd")&lt;br /&gt;for incoming traffic.&lt;br /&gt;&lt;br /&gt;You can get this by using rules like:&lt;br /&gt;&lt;br /&gt;# ipfw add 100 divert natd ip from any to any in recv $OUTGOING_INTERFACE&lt;br /&gt;&lt;br /&gt;Put all the pipe rules here&lt;br /&gt;&lt;br /&gt;# ipfw add 4000 divert natd ip from any to any out xmit $OUTGOING_INTERFACE&lt;br /&gt;&lt;br /&gt;NOTE:&lt;br /&gt;1. Remember to set sysctl variable "net.inet.ip.fw.one_pass" to 0, which prevents packets from&lt;br /&gt;not being reinjected into the firewall.&lt;br /&gt;&lt;br /&gt;2. You may also want to put a "skipto" rule after ip to pipe assigning (if you are using lots of such rules).&lt;br /&gt;&lt;br /&gt;3. Personally I'm using ipnat+dummynet, which works fine for bigger networks. natd is not&lt;br /&gt;fast, as it works in userland. ipnat is entirely kernel attached, so it's faster.&lt;br /&gt;&lt;br /&gt;4. If using FreeBSD 4.x make sure you apply the ipfw/ipfilter order patch (lookup for "ipfw ipnat order patch" in google)&lt;br /&gt;&lt;br /&gt;5. Assign appropriate "queue" values for each pipe depending on the pipe bw parameter.&lt;br /&gt;&lt;br /&gt;6. In FreeBSD 5.5? 6.X you can even simplify the ruleset, read about "tablearg" parameter for ipfw!&lt;br /&gt;&lt;br /&gt;7. Tune all "net.inet.ip.dummynet.*" sysctls if there are lots of hosts in your network, and there's a danger of creating lots of dynamic pipes.&lt;br /&gt;&lt;br /&gt;8. Some guys use pf+dummynet for FreeBSD 6.X nat. I think it's tricky too, as pf is a great firewall too!&lt;br /&gt;&lt;br /&gt;Some useful links:&lt;br /&gt;&lt;a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/firewalls-ipfw.html"&gt;http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/firewalls-ipfw.html&lt;/a&gt;&lt;br /&gt;&lt;a href="http://info.iet.unipi.it/~luigi/ip_dummynet/"&gt;http://info.iet.unipi.it/~luigi/ip_dummynet/&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-8893139915327363723?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/8893139915327363723/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=8893139915327363723' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/8893139915327363723'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/8893139915327363723'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2007/06/freebsd-qos-with-freebsd-dummynet.html' title='[EN] FreeBSD QOS with FreeBSD DUMMYNET'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-1675471661506594923</id><published>2007-05-20T01:43:00.000-07:00</published><updated>2007-05-20T02:53:59.369-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='jail'/><category scheme='http://www.blogger.com/atom/ns#' term='admin'/><category scheme='http://www.blogger.com/atom/ns#' term='freebsd'/><category scheme='http://www.blogger.com/atom/ns#' term='unix'/><category scheme='http://www.blogger.com/atom/ns#' term='vps'/><title type='text'>[EN] FreeBSD multiple Jails with "ezjail"</title><content type='html'>Linux has a great support for VPS systems, so that you can easily create&lt;br /&gt;multiple virtual environments using xen f.e.&lt;br /&gt;&lt;br /&gt;As my favourite OS is FreeBSD I've decided to look for a similar solution.&lt;br /&gt;I've been aware of great "jail" feature, but managing multiple jails&lt;br /&gt;is not that handy as it is in linux.&lt;br /&gt;&lt;br /&gt;Recently, I found a great solution , "ezjail". ( /usr/ports/sysutils/ezjail )&lt;br /&gt;&lt;br /&gt;"ezjail" is a shell script which lets you easily:&lt;br /&gt;&lt;br /&gt;- create new jails&lt;br /&gt;- running/shutting down jails&lt;br /&gt;- update existing jails&lt;br /&gt;&lt;br /&gt;You can create jail environment as:&lt;br /&gt;- file system in your existing os&lt;br /&gt;- file system in either plain, gdbe or geli encrypted image&lt;br /&gt;&lt;br /&gt;Before you begin, make sure you are familiar with jails by reading:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails.html"&gt;http://www.freebsd.org/doc/en_US.ISO8859-1/books/handbook/jails.html&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;A very interesting note is that "ezjail" doesn't create a completely new base system for new jails.&lt;br /&gt;Instead it makes use of mount_nullfs and create "ro" mounts of the main base system&lt;br /&gt;dirs like "/bin", "/sbin" etc.&lt;br /&gt;&lt;br /&gt;When you create a new jail, it creates the "basejail" which in my case was 114MB size.&lt;br /&gt;Any other jails (in case you don't do any other customizations) is 2MB large!.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Let's get started with "ezjail" !&lt;br /&gt;&lt;br /&gt;First, create the base jail system.&lt;br /&gt;&lt;br /&gt;# ezjail-admin install&lt;br /&gt;&lt;br /&gt;This will fetch files needed for base system according to your current os version (`uname -r`)&lt;br /&gt;&lt;br /&gt;# ezjail-admin create testjail 192.168.3.1&lt;br /&gt;where IP is the IP you assing to your jail. Make sure it's already existing and set up.&lt;br /&gt;&lt;br /&gt;Let's list existing jails now.&lt;br /&gt;&lt;br /&gt;# ezjail-admin list&lt;br /&gt;STA JID   IP              Hostname                     Root Directory&lt;br /&gt;--- ----- --------------- ---------------------------- -------------------------&lt;br /&gt;DS  N/A   192.168.3.21    testjail                     /usr/jails/testjail&lt;br /&gt;#&lt;br /&gt;&lt;br /&gt;"DS" flags mean that it's  a Directory Based jail and it's Stopped.&lt;br /&gt;&lt;br /&gt;To create a geli encrypted image you would:&lt;br /&gt;&lt;br /&gt;# ezjail-admin create  -s 200M -c eli gelibasedjail 192.168.3.22&lt;br /&gt;200+0 records in&lt;br /&gt;200+0 records out&lt;br /&gt;209715200 bytes transferred in 12.010512 secs (17460971 bytes/sec)&lt;br /&gt;Initialising crypto device. Enter a new passphrase twice...&lt;br /&gt;Enter new passphrase:&lt;br /&gt;Reenter new passphrase:&lt;br /&gt;&lt;br /&gt;Your jails is ready!&lt;br /&gt;You can easily attach your jail filesystem:&lt;br /&gt;&lt;br /&gt;# ezjail-admin config -i attach gelibasedjail&lt;br /&gt;Attaching eli device for image jail ...&lt;br /&gt;Enter passphrase:&lt;br /&gt;&lt;br /&gt;Let's check the system mounts&lt;br /&gt;# mount&lt;br /&gt;...&lt;br /&gt;/dev/md0.eli on /usr/jails/gelibasedjail (ufs, local)&lt;br /&gt;...&lt;br /&gt;&lt;br /&gt;and go into your jail file system:&lt;br /&gt;&lt;br /&gt;# cd /usr/jails/gelibasedjail&lt;br /&gt;&lt;br /&gt;# ls&lt;br /&gt;.snap           bin             etc             media           rescue          sys             var&lt;br /&gt;COPYRIGHT       boot            lib             mnt             root            tmp&lt;br /&gt;basejail        dev             libexec         proc            sbin            usr&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;To start your jails on reboot, add ezjail_enable="YES" entry into your /etc/rc.conf file.&lt;br /&gt;&lt;br /&gt;After reboot all your jails (which do not require password) will start.&lt;br /&gt;&lt;br /&gt;You can also start/shutdown particular jails with:&lt;br /&gt;&lt;br /&gt;# /usr/local/etc/rc.d/ezjail.sh start|stop  gelibasedjail&lt;br /&gt;&lt;br /&gt;You would ask "What if I want some customizations when creating new jails?".&lt;br /&gt;&lt;br /&gt;"ezjail" comes with "flavours" functionality.&lt;br /&gt;&lt;br /&gt;Let's say you want to create a new bunch of jails for HTTP web serving.&lt;br /&gt;Your customers will put the Web data in /web/sites, and you want to avoid creating&lt;br /&gt;this directories anytime you create a new jail.&lt;br /&gt;&lt;br /&gt;With ezjail it's simple!&lt;br /&gt;&lt;br /&gt;# cd /usr/jails/flavours/&lt;br /&gt;# mkdir httpd&lt;br /&gt;# cd httpd&lt;br /&gt;# mkdir -p /web/sites&lt;br /&gt;&lt;br /&gt;Now when creating new jail let "ezjail" know about the flavour:&lt;br /&gt;# ezjail-admin create -f httpd newjail JAILIP&lt;br /&gt;&lt;br /&gt;This will create a new jail with /web/sites directory created within your new jail!&lt;br /&gt;The directory tree will recursively be copied to your new jail.&lt;br /&gt;&lt;br /&gt;You can also perform other desired actions like running script when initiating a new jail install.&lt;br /&gt;Create users, fetch packages.. do whatever you want.&lt;br /&gt;&lt;br /&gt;Put the "ezjail-flavour" script in your new flavour jail definition (/usr/jails/httpd/ezjail-flavour) in my example.&lt;br /&gt;&lt;br /&gt;Hope I convinced you to try "ezjail".&lt;br /&gt;&lt;br /&gt;Some notes:&lt;br /&gt;- it does create/delete /etc/fstab.jailname entries, so you don't have to worry about filesystem mountpoints after reboot. (you can avoid running specified jail at startup by `ezjail-admin config -r run|norun jailname` command)&lt;br /&gt;- it's about creating/deleting/running/shutting down jails at the moment.  It does not allow you&lt;br /&gt;to manage jail f.e. resource usage. Look at: &lt;a href="http://wiki.freebsd.org/JailResourceLimits"&gt;http://wiki.freebsd.org/JailResourceLimits &lt;/a&gt;for more information.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;Look at the URL below, to find out more about the functionality of "ezjail".&lt;br /&gt;Also, consider donation :)&lt;br /&gt;&lt;br /&gt;&lt;span style="text-decoration: underline;"&gt;&lt;a href="http://erdgeist.org/arts/software/ezjail/"&gt;http://erdgeist.org/arts/software/ezjail&lt;/a&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-1675471661506594923?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/1675471661506594923/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=1675471661506594923' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/1675471661506594923'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/1675471661506594923'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2007/05/en-freebsd-multiple-jails-with-ezjail.html' title='[EN] FreeBSD multiple Jails with &quot;ezjail&quot;'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-6489865156269836311</id><published>2007-04-26T01:30:00.003-07:00</published><updated>2007-04-26T02:09:35.058-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='user'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='extending'/><title type='text'>[EN] Django extending User, custom User methods</title><content type='html'>Django doesn't allow to subclass the User model yet.&lt;br /&gt;&lt;br /&gt;Each Django model lets you easily create model methods.&lt;br /&gt;Behind the scene, each django model has its own methods, f.e. save()&lt;br /&gt;which saves the model data into the database.&lt;br /&gt;&lt;br /&gt;Django provides the lightweight User framework in "django/contrib/auth/",&lt;br /&gt;where "User" model is defined with fields:&lt;br /&gt;&lt;br /&gt;username, password, is_staff, first_name, last_name, email, date_joined, last_login, &lt;br /&gt;is_superuser, is_active&lt;br /&gt;&lt;br /&gt;What if we need the user model with additional data like: age, location ?&lt;br /&gt;&lt;br /&gt;The answer is: "extending the User model" by creating a new model&lt;br /&gt;and linking it with "User" model via ForeignKey.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;from django.contrib.auth.models import User&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; Userprofile(models.Model):&lt;br /&gt;        user = models.ForeignKey(User, unique=True)&lt;br /&gt;        age = models.IntegerField()&lt;br /&gt;        location = models.CharField(maxlength=&lt;span style="color: #115511"&gt;"100"&lt;/span&gt;, verbose_name&lt;span style="color: #115511"&gt;"Country"&lt;/span&gt;)&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To create a new user, django comes with a special "create_user" method.&lt;br /&gt;&lt;pre&gt;user = User.objects.create_user(&lt;span style="color: #115511"&gt;'robert'&lt;/span&gt;, &lt;span style="color: #115511"&gt;'rsome@email'&lt;/span&gt;, &lt;span style="color: #115511"&gt;'somepassword'&lt;/span&gt;)&lt;br /&gt;user.save()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;You could do this also using the standard model create like:&lt;br /&gt;&lt;pre&gt;user = User(username=&lt;span style="color: #115511"&gt;'someusername'&lt;/span&gt;, is_active=True, email=&lt;span style="color: #115511"&gt;'some@email'&lt;/span&gt;, first_name=&lt;span style="color: #115511"&gt;'john'&lt;/span&gt;, last_name=&lt;span style="color: #115511"&gt;'doe'&lt;/span&gt;)&lt;br /&gt;user.save()&lt;br /&gt;user.set_password(&lt;span style="color: #115511"&gt;'somepassword'&lt;/span&gt;)&lt;br /&gt;user.save()&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;As we have a new User record, to create a new "linked" UserProfile you would:&lt;br /&gt;&lt;pre&gt;user = User.objects.get(name=&lt;span style="color: #115511"&gt;'someusername'&lt;/span&gt;)&lt;br /&gt;user.userprofile_set.create(age=22, location=&lt;span style="color: #115511"&gt;'Poland'&lt;/span&gt;)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Django will automagically create the new UserProfile with "user" ForeignKey pointing &lt;br /&gt;to the right User instance. Cool !&lt;br /&gt;&lt;br /&gt;Question! How do I work on two separated models? Do I need to grab the UserProfile&lt;br /&gt;instance for each request.user I operate in my views ?&lt;br /&gt;&lt;br /&gt;Answer: Normally, you woule have to use the code below:&lt;br /&gt;&lt;pre&gt;userprofile = Userprofile.objects.get(user=request.user)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Django comes with a special settings.py variable "AUTH_PROFILE_MODULE' which should point to your Userprofile model.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;AUTH_PROFILE_MODULE = 'yourapp.Userprofile'&lt;br /&gt;&lt;br /&gt;which lets you easily get into the "UserProfile" by using the "get_profile()" method.&lt;br /&gt;&lt;br /&gt;Example: (in your either views.py or template):&lt;br /&gt;&lt;br /&gt;location = request.user.get_profile().location&lt;br /&gt;{{ user.get_profile.location }}&lt;br /&gt;&lt;br /&gt;Note:&lt;br /&gt;user_profile() does not only allows you to get the model data.&lt;br /&gt;It allows you to get the model methods as well.&lt;br /&gt;&lt;br /&gt;Example:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; Userprofile(models.Model):&lt;br /&gt;        user = models.ForeignKey(User, unique=True)&lt;br /&gt;        age = models.IntegerField()&lt;br /&gt;        location = models.CharField(maxlength=&lt;span style="color: #115511"&gt;"100"&lt;/span&gt;)&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; __str__(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.location&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; is_of_age(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; self.age &amp;lt; 18:&lt;br /&gt;                        &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; False&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;                        &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; True&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;This lets you do some conditioning in your views:&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; request.user.get_profile().is_of_age():&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;print&lt;/b&gt;&lt;/span&gt; &lt;span style="color: #115511"&gt;"Yes, I will sell you this beer"&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Delicious!&lt;br /&gt;&lt;br /&gt;Another +1 for Django ! &lt;br /&gt;&lt;br /&gt;Links for reading:&lt;br /&gt;http://www.djangoproject.com/documentation/authentication/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-6489865156269836311?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/6489865156269836311/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=6489865156269836311' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6489865156269836311'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/6489865156269836311'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2007/04/en-django-extending-user_2281.html' title='[EN] Django extending User, custom User methods'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-1148195454380051662.post-4215653053442287769</id><published>2007-04-25T04:55:00.000-07:00</published><updated>2007-04-26T02:15:50.109-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='django'/><category scheme='http://www.blogger.com/atom/ns#' term='python'/><category scheme='http://www.blogger.com/atom/ns#' term='models'/><category scheme='http://www.blogger.com/atom/ns#' term='managers'/><title type='text'>[EN] Django model managers, Do Not Repeat Yourself !</title><content type='html'>I've recently come up with a great django feature "model Managers".&lt;br /&gt;&lt;br /&gt;Each django model has it's own manager class, which can be overriden by your custom class.&lt;br /&gt;&lt;br /&gt;Let's say there's a model containing fields:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; Person(models.Model):&lt;br /&gt;        name = models.CharField(maxlength=&lt;span style="color: #115511"&gt;"100"&lt;/span&gt;, blank=False, verbose_name=&lt;span style="color: #115511"&gt;"Your name"&lt;/span&gt;)&lt;br /&gt;        age = models.IntegerField(verbose_name="Your age")&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; __str__(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.name&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;You need to use this model in many places, and you need to select people by age and mark&lt;br /&gt;them as child, teen, older.&lt;br /&gt;&lt;br /&gt;Each time you select them you would need to crate a queryset like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;children = Person.objects.filter(age__lt=13)&lt;br /&gt;teen = Person.objects.filter(age__gte=13).filter(age__lt=18)&lt;br /&gt;older = Person.objects.filter(age__gte=18)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Anytime you use this function, you would need to write the filter statements.&lt;br /&gt;&lt;br /&gt;Thanks to model managers, you can do it once, and use it in your code anywhere.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; PersonManager(models.Manager):&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; get_children(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.filter(age__lt=13)&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; get_teens(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.filter(age__ge=13).filter(age_lt=18)&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; get_olders(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.filter(age__gte=18)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and put:&lt;br /&gt;objects = PersonManger() in your model class so the class looks like:&lt;br /&gt;&lt;br /&gt;from django.db import models&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; Person(models.Model):&lt;br /&gt;        name = models.CharField(maxlength=&lt;span style="color: #115511"&gt;"100"&lt;/span&gt;, blank=False, verbose_name=&lt;span style="color: #115511"&gt;"Your name"&lt;/span&gt;)&lt;br /&gt;        age = models.IntegerField(verbose_name="Your age")&lt;br /&gt;&lt;br /&gt;        objects = PersonManger()&lt;br /&gt;&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; __str__(self):&lt;br /&gt;                        &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.name&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;To select teens, you can use: Person.objects.get_teens().&lt;br /&gt;You can use any standard queryset options like .filter, .exclude etc, for example:&lt;br /&gt;&lt;br /&gt;To get teens, with name not starting with "s".&lt;br /&gt;Person.objects.get_teens.exclude(name__startswith: "s")&lt;br /&gt;&lt;br /&gt;Also, you can change parameters for model managers functions.&lt;br /&gt;&lt;br /&gt;Let's say you want to select teens, olders, children with name starting with some letter.&lt;br /&gt;&lt;br /&gt;Modify your model manager functions, so they look like (I will modify just the one here).&lt;br /&gt;&lt;br /&gt; &lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; get_teens(self, name_filter_letter=None):&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;if&lt;/b&gt;&lt;/span&gt; name_filter_letter &lt;span style="color: #3333CC"&gt;&lt;b&gt;is&lt;/b&gt;&lt;/span&gt; None:&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.filter(age__ge=13, age_lt=18)&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;else&lt;/b&gt;&lt;/span&gt;:&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; self.filter(age__ge=13).filter(age__lt=18).filter(name__startswith=name_filter_letter)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;And use it like:&lt;br /&gt;Person.objects.get_teens("s")&lt;br /&gt;&lt;br /&gt;Custom managers can do many other things, they are a standard python methods.&lt;br /&gt;&lt;br /&gt;Note that you don't need to use the name:&lt;br /&gt;objects = PersonManager()&lt;br /&gt;&lt;br /&gt;You can use your own name as well:&lt;br /&gt;persons = PersonManager()&lt;br /&gt;&lt;br /&gt;which results in:&lt;br /&gt;Person.persons.get_teens()&lt;br /&gt;&lt;br /&gt;One more thing:&lt;br /&gt;You can go deeply and override the models.Manager get_query_set() method, for example:&lt;br /&gt;&lt;br /&gt;You want to grab teens from the model:&lt;br /&gt;&lt;br /&gt;Create model subclass like:&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;span style="color: #3333CC"&gt;&lt;b&gt;class&lt;/b&gt;&lt;/span&gt; PersonTeensManager(models.Manager):&lt;br /&gt;        &lt;span style="color: #3333CC"&gt;&lt;b&gt;def&lt;/b&gt;&lt;/span&gt; get_query_set(self):&lt;br /&gt;                &lt;span style="color: #3333CC"&gt;&lt;b&gt;return&lt;/b&gt;&lt;/span&gt; super(PersonTeensManager, self).get_query_set().filter(age__lt=18).filter(age__gte=3)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;and put:&lt;br /&gt;&lt;br /&gt;teens = PersonTeensManager() in your model class.&lt;br /&gt;&lt;br /&gt;In your views, use the queryset:&lt;br /&gt;&lt;br /&gt;teens = Person.teens.all()&lt;br /&gt;&lt;br /&gt;Isn't that simple?!&lt;br /&gt;&lt;br /&gt;For more documentation take a look here:&lt;br /&gt;http://www.djangoproject.com/documentation/models/custom_managers/&lt;br /&gt;http://www.djangoproject.com/documentation/models/get_object_or_404/&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/1148195454380051662-4215653053442287769?l=mirobetm.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://mirobetm.blogspot.com/feeds/4215653053442287769/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=1148195454380051662&amp;postID=4215653053442287769' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/4215653053442287769'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/1148195454380051662/posts/default/4215653053442287769'/><link rel='alternate' type='text/html' href='http://mirobetm.blogspot.com/2007/04/django-model-managers-do-not-repeat.html' title='[EN] Django model managers, Do Not Repeat Yourself !'/><author><name>Robert M.</name><uri>http://www.blogger.com/profile/05564037158651785633</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry></feed>
