models

Get all Django records created since last login

牧云@^-^@ 提交于 2019-12-12 03:23:37
问题 Using Django models, is there a filter I can use to select all records created after a certain date? I'm not sure what syntax or filter I should use to get all records newer than my last_login. I wouldn't mind doing it with a Q advanced query, but the simpler the better! 回答1: Actually, you don't need the current datetime if you want to select all records created after a certain date. Just use a filter with a lookup like: field_date__gte=last_login. It's not necessary to use range here. For

Ruby on Rails: Searching two models in one search

半城伤御伤魂 提交于 2019-12-11 15:41:10
问题 I have a search page where a user can search for different projects, using different dropdown menus. They can search for more than one field at a time, and the search will return something if it finds a project that matches all fields. Heres my search action in my project controller: def search @search = params[:client], params[:industry], params[:tech], params[:keywords] @project_search = Project.search(*@search).order(sort_column + ' ' + sort_direction).paginated_for_index(per_page, page)

Web-scraping Rails App Getting Over-Modelled?

為{幸葍}努か 提交于 2019-12-11 11:29:46
问题 I'd like some opinons on whether I'm over-modeling my app. In this app, I'm saving off html meta data I download from websites. I download the meta tags and make them part of an an array. For each element in the meta_tags array, I want to save that element. But I need to account for situations where, for instance, there are two robots meta metas (one for index and one for follow). So my initial thought was to solve this by creating a "meta_tags" table and saving any meta tags off to their.

How to execute CASCADE on delete?

拟墨画扇 提交于 2019-12-11 11:17:57
问题 I have this model in Django, where a person has the same information from the user provided by Django plus a little bit more information. When I create a new person it requires to create a new user also, that's fine. But when I delete a person the user still remains on my database. What am I missing here ? I would like to delete the user too. class Person(models.Model): user = OneToOneField(User) gender = CharField(max_length=1, choices=GenderChoices, blank=True, null=True) birth_date =

How Can I do this …Multiples models on view MVC 5

半城伤御伤魂 提交于 2019-12-11 10:56:40
问题 I want to do this view .. I have a model call Product Options and I need to bring on the view the name or photo path for different tables public class ProductOption { public int id { get; set; } [Display(Name = "Product")] public int ProductId { get; set; } [Display(Name = "Group")] public int GroupId { get; set; } [Display(Name = "Option")] public int OptionId { get; set; } [Display(Name = "Price")] public decimal priceIncrement { get; set; } } } This are the Product Model: public class

How to prevent updating a single attribute in Rails?

别说谁变了你拦得住时间么 提交于 2019-12-11 10:31:34
问题 When a form is submitted, how to prevent a single attribute from being updated in Rails? All other attributes should be updated. Is it before_save , attr_reader or some other way? If using before_save , how to access to the attributes hash? Rails 3.0.7 回答1: Check out attr_protected . Class YourModel << ActiveRecord::Base attr_protected :the_one_column, as: :update # ... end Now as part of a call to update_attributes , you'd specify the :update role, for example klass = YourModel.find(some_id)

Django TimeField format

ε祈祈猫儿з 提交于 2019-12-11 10:19:57
问题 I have time in format something like there: "10 a.m., noon". I want to have in format: 10:00, 12:00, 15:00 etc. I've tried in my html file: {{ value|time:"H:M" }} I also tried in my settings TIME_INPUT_FORMATS = ('%H:%M',) Nothing work. In my models I have: time = models.TimeField(blank=True, null=True) views.py times= Hours_classes.objects.all() context = {'teacher_id': teacher_id, 'query_results': query_results, 'times': times} return render(request, 'planner/teacher.html', context) teacher

django的各种查询

孤街浪徒 提交于 2019-12-11 09:42:44
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> 以一个学生类为例: class Student(models.Model): id= models.FloatField(primary_key=True,related_name='blog') name= models.CharField(max_length=20, blank=True, null=True) age=models.FloatField(blank=True, null=True) class Meta: managed = False db_table = 'student' class Blog(models.Model): name = models.CharField(max_length=100) tagline = models.TextField() student=models.ForeignKey(Student) 1.基础查询: Student.objects.all();查询全部(Object是你要查的表对应的model名,后面是Django语法) 相当于 " select * from student" Object.objects.filter(过滤条件);filter里面的内容相当于sql语句where后面的过滤条件,多个过滤条件用逗号隔开,相当于sql中的

Django “emulate” database trigger behavior on bulk insert/update/delete

我与影子孤独终老i 提交于 2019-12-11 09:42:39
问题 It's a self expaining question but here we go. I'm creating a business app in Django, and i didn't wanted to "spread" all the logic across app AND database, but in the other hand, i didn't wanted to let the Database handle this task (its possible through the use of Triggers). So I wanted to "reproduce" the behavior of the Databse Triggers, but inside the Model Class in Django (um currently using Django 1.4). After some research, I figured out that with single objects, I could override the

CakePHP 1.3 contain not building associations correctly

烂漫一生 提交于 2019-12-11 08:58:30
问题 this is my first question here. I'm having an issue with containable behavior in cakephp 1.3. The issue is as follows: I have a Deliverable model with the following associations: class Deliverable extends AppModel { var $name = 'Deliverable'; var $displayField = 'name'; var $actsAs = array('Containable'); var $belongsTo = array( 'Asset' => array( 'className' => 'Asset', 'foreignKey' => 'asset_id', 'dependent' => false ), 'DelRouteName' => array( 'className' => 'DelRouteName', 'foreignKey' =>