models

Rails: Pass parameter from view to controller

混江龙づ霸主 提交于 2020-01-14 10:34:29
问题 I have the following models in rails : class Task < ActiveRecord::Base attr_accessible :description, :name, :project belongs_to :project validates :name, :presence => true end class Project < ActiveRecord::Base attr_accessible :name has_many :tasks end I have a view that lists the projects available On click on any of the project I want to open up a page that lists all the tasks in the clicked project. Now the question is how do I pass the project id? I also want the project id to be visible

drf-过滤组件

白昼怎懂夜的黑 提交于 2020-01-14 09:56:08
目录 filter过滤类源码分析 排序组件 OrderingFilter 搜索组件 SearchFilter 自定义limit限制条件过滤器 筛选插件 djanog_filter 分类筛选 DjangoFilterBackend 区间筛选(自定义区间筛选类) 分页 普通分页 PageNumberPagination 偏移分页 LimitOffsetPagination 游标分页 CursorPagination filter过滤类源码分析 我们从视图类中群查接口入口,去看看它内部是怎么实现过滤的 首先我们进入ListAPIView类中 实现群查功能的是它的第一个父类mixins中调用的,我们进入它的第一个父类 我们看到它的群查接口有一个 filter_queryset 方法,此时一定要清楚属性的查找顺序, 此时的self是指的视图类,如果视图类中没有这个方法,那就去它的父类中去找,那我这里就直接告诉你它是在GenericAPIView通用视图类中 ''' 源码 ''' def filter_queryset(self, queryset): """ Given a queryset, filter it with whichever filter backend is in use. You are unlikely to want to override this method,

day84

我是研究僧i 提交于 2020-01-14 09:37:17
目录 filter过滤类源码分析 排序组件 OrderingFilter 搜索组件 SearchFilter 自定义limit限制条件过滤器 筛选插件 djanog_filter 分类筛选 DjangoFilterBackend 区间筛选(自定义区间筛选类) 分页 普通分页 PageNumberPagination 偏移分页 LimitOffsetPagination 游标分页 CursorPagination filter过滤类源码分析 我们从视图类中群查接口入口,去看看它内部是怎么实现过滤的 首先我们进入ListAPIView类中 实现群查功能的是它的第一个父类mixins中调用的,我们进入它的第一个父类 我们看到它的群查接口有一个 filter_queryset 方法,此时一定要清楚属性的查找顺序, 此时的self是指的视图类,如果视图类中没有这个方法,那就去它的父类中去找,那我这里就直接告诉你它是在GenericAPIView通用视图类中 ''' 源码 ''' def filter_queryset(self, queryset): """ Given a queryset, filter it with whichever filter backend is in use. You are unlikely to want to override this method,

Inheritance in Laravel framework

回眸只為那壹抹淺笑 提交于 2020-01-14 06:47:05
问题 Is possibile to use inheritance in laravel model? I explain: is possible to exend a model, which extends eloquent class? class A extends Eloquent { } class B extends A { } A e B are also 2 different tables and B has A_id as foreignkey and other fields. How could be the constructor of class B? is it a ragionable solution or better use hasOne relationship? no every A object are also B object. Es. user and teacher Thank you 回答1: I’m having difficulty understanding your supplementary details, but

Yii2 + Redis as Database

China☆狼群 提交于 2020-01-13 05:26:31
问题 I want to use Yii2 and redis as database. So far, I got Redis ActiveRecord Class for Yii2 from Here. link1 link2 but, I got a problem. WHY THIS CLASS ADDS ANYTHING AS HASH IN REDIS???? Above that I cant Find in which pattern it Insert data. I add one user and it will add a user under user:xxx namespace and another record under s:user:xxx and so on but none of theme has any fields that i defined in attributes!! only contain IDs. I know that a Key-value type database and RDBMS are different and

How can I make all CharField in uppercase direct in model?

淺唱寂寞╮ 提交于 2020-01-12 08:49:48
问题 I tried to use UpperCase in all my CharField, in all my Django Model. Today I have some code in my save method: def save(self, *args, **kwargs): for field_name in ['razao_social', 'nome_fantasia', 'cidade', 'endereco','bairro', 'uf', 'cli_parc_nomeparc', 'cli_repr_nomerepr']: val = getattr(self, field_name, False) if val: setattr(self, field_name, val.upper()) super(Pessoa, self).save(*args, **kwargs) But its take some time. There`s any method to put some uppercase=True in my models? Thanks.

简易的图书管理系统代码(实现对数据的增删改查)

别来无恙 提交于 2020-01-11 16:30:08
目录 简易的图书管理系统 简易的图书管理系统 urls.py from django.conf.urls import url from django.contrib import admin from app01 import views urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^$', views.home, name='home1'), url(r'^book_list', views.book_list, name='book_show'), url(r'^add_book', views.add_book, name='add'), url(r'^edit_book/(?P\d+)', views.edit_book, name='edit'), url(r'^delete_book/(\d+)', views.delete_book, name='delete') ] models.py from django.db import models # Create your models here. # 图书表 class Book(models.Model): # 书名 title = models.CharField(max_length=64) # 出版日期 publish_date =

Django migration with python3.6 ERROR:root:code for hash sha3_224 was not found

倾然丶 夕夏残阳落幕 提交于 2020-01-11 04:58:28
问题 Hello I read Django tutorials and I have an error related to specific sha3_224 hash function during the migration process. How to solve this problem? Thank you. (venv) linuxoid@linuxoid-ThinkPad-L540:~/myprojects/myproject$ python manage.py makemigrations ERROR:root:code for hash sha3_224 was not found. Traceback (most recent call last): File "/home/linuxoid/myprojects/venv/lib/python3.6/hashlib.py", line 121, in __get_openssl_constructor f = getattr(_hashlib, 'openssl_' + name)

Django之models高级进阶技术详解

谁说胖子不能爱 提交于 2020-01-10 19:50:48
目录 一、常用字段 1.AutoField 2.IntegerField 3.CharField 4.自定义及使用char 5.DateField 6.DateTimeField 二、字段合集 三、字段参数 1.null 2.unique 3.db_index 4.default 四、DateField和DateTimeField 1.auto_now_add 2.auto_now 五、关系字段 1.ForeignKey 一对多 字段参数 1.to 2.to_field 3.on_delete 4.db_constraint 5.其余字段参数 2.OneToOneField 一对一 字段参数 1.to 2.to_field 3.on_delete 3.ManyToManyField 多对多三种创建方式 ①全自动(常见) ②纯手动(了解) ③半自动(推荐) 六、choices参数 1.用户表举例 2.基本运用 七、数据库查询优化(面试) 1.惰性查询 2.only与defer的用法 noly的使用: defer的使用: 大白话总结: 3.selected_related与prefetch_related 八、Djangi ORM 中如何开启事物 九、MTV与MVC模型 一、常用字段 1.AutoField int自增列,必须填入参数 primary_key=True