Django 1.7 + Scrapy

Today I am going to share how to use Scrapy and Django together to crawl to a website and store scrapped data to Database using Django. First, let us build a Django application using the following commands. pip install django==1.7 django-admin.py startproject example_project cd example_project Inside the example_project directory, we will create a django app named app: python manage.py startapp app Then, we will update the models.py like this: from django.db import models class ExampleDotCom(models.Model): title = models.CharField(max_…

Keep reading

Make a Blog using Django Part 2

From previous post, you have configured and ran django, also added admin site to the django. To view the working source of this tutorial, check here at: https://github.com/ruddra/myblog Now click on the myblog section and click add to add new blog. You can create new tags using Tags section of the admin page or clicking the (+) button right beside the Tags section on the new blog creation page, marked with blue circle in the previous image. After successfully adding a new blog, you can see it…

Keep reading

Make a Blog using Django Part 1

"Making a blog using django" is probably the most made tutorial of Django. This post is no different. But I made this in my own way using some of django's built-in features so that less coding is required and making it more understandable with minimum packages to use. To view the working source of this tutorial, check here at: https://github.com/ruddra/myblog Before jumping to the main event, see if you have these installed in your pc: 1. Python 3 installed in the computer. (Or python 2.7…

Keep reading

Change Column Header Dynamically in Django Tables2

Django Tables2 is a package which displays table directly from queryset. It shows column header based on object's attribute's name. But if someone wants to override it, how can he/she do that? Here is a easy solution. Suppose we have a model class like this: class SomeModel(models.Model): somevalue = models.CharField() And we want to show table column somevalue to overridenvalue Table Class: class SomeTable(tables.Table): def __init__(self, *args, _overriden_value="",**kwargs): super().__init__(*args, **kwargs) self.base_columns['somevalue'].verbose_name = _overriden_value class Meta:…

Keep reading

Dynamically constructing filters based on string input using SQLAlchemy

Here I am going to write a dynamic filter. This filter is made for python 3. It will take query or model class and filter condtion as input, It will return filtered query based on those filter condition. This is constructed using this SO answer. Function: class DynamicFilter(ModelHelper): def __init__(self, query=None, model_class=None, filter_condition=None): super().__init__(*args, **kwargs) self.query = query self.model_class = model_class self.filter_condition = filter_condition def get_query(self): ''' Returns query with all the objects :return: '''…

Keep reading