반응형

pycharm 설치 - 나만의 환경 설정하기


환경 : pycharm community edition 4.0



1. 메뉴  -->  view --> toolbar , tool buttons 체크하여 추가하기.


2.line number 보이기


3. highlight occurrences 활성화 확인하기

   


-- cccurrences 색깔 바꾸기



    ---> 원하는 색으로 바꾸면 된다.

   -- 저장시에 scheme 을 본인 원하는 이름으로 저장하면 된다.



4. PEP8 체크 해제하기

























반응형
Posted by 자유프로그램
,
반응형

장고 - django 1.7 tutorial 2 정리



환경 : 


참고 :  https://docs.djangoproject.com/en/1.7/intro/tutorial02/



Writing your first Django app, part 2


이번 tutorial 2 에서는 web-poll application 만들면서, 장고가 자동으로 만들어주는 admin 사이트에 초점!


**  adimin site 는 방문자를 위한게 아님, site manager 를 위한 것임.



Creating an admin user


먼저 admin site 에 로그인 할수있는 사용자를 만들자.

$ python manage.py createsuperuser

이후에는 사용자이름, e-mail, 암호설정 한다.




Start the development server


기본적으로 장고 admin site 는 활성화 되어있으므로, 개발 서버를 실행해보자.


$ python manage.py runserver


이후에 웹브라우저에서 해당  "/admin/" 으로 접속해보자.

ex)   http://127.0.0.1:8000/admin/ 


성공시에 아래 화면 보임.





Enter the admin site


위에서 만든 superuser 계정으로 로그인하여 장고 admin index 페이지를 보자!



Groups, Users 와 같은 편집가능한 content 가 보일것이다. 

이는 장고에 포함된 authentication framework ( django.contrib.auth ) 에서 제공하는 기능이다.



Make the poll app modifiable in the admin


우리가 tutorial 1 에서 만든 polls app 이 admin index 페이지에서는 안보인다!


Question 객체가 admin interface 를 갖도록 해야한다. 이를위해 polls/admin.py 파일을 아래와 같이 수정한다.


polls/admin.py
from django.contrib import admin
from polls.models import Question

admin.site.register(Question)



Explore the free admin functionality


이제 Question 을 등록했으므로, 장고에서 admin index 페이지에 이를 보여준다!



위 화면에서 "Question" 를 선택하면, question 에 대한 "change list" 페이지가 보인다.

여기서 database 에 저장한 모든 질문 항목들을 보여준다.

현재는 tutorial 1 에서 우리가 생성한 "What's up?" 질문 항목만 있다. 



수정하기 위해 "What's up?" 질문 항목을 click 해보자.






Customize the admin form















반응형
Posted by 자유프로그램
,
반응형

장고 - Django 1.7 -- Manager 명명법 ; _set 사용법



참고 : https://docs.djangoproject.com/en/1.7/topics/db/queries/#related-objects




Making queries


from django.db import models

class Blog(models.Model):
    name = models.CharField(max_length=100)
    tagline = models.TextField()

    def __str__(self):              # __unicode__ on Python 2
        return self.name

class Author(models.Model):
    name = models.CharField(max_length=50)
    email = models.EmailField()

    def __str__(self):              # __unicode__ on Python 2
        return self.name

class Entry(models.Model):
    blog = models.ForeignKey(Blog)
    headline = models.CharField(max_length=255)
    body_text = models.TextField()
    pub_date = models.DateField()
    mod_date = models.DateField()
    authors = models.ManyToManyField(Author)
    n_comments = models.IntegerField()
    n_pingbacks = models.IntegerField()
    rating = models.IntegerField()

    def __str__(self):              # __unicode__ on Python 2
        return self.headline



Related objects


One-to-many relationships

Forward


- ForeignKey 를 가지고 있는 model instance 는 , 모델의 attribute 르 통해 related (foreign) object 에 접근할수있다.

Example:

>>> e = Entry.objects.get(id=2)
>>> e.blog # Returns the related Blog object.



Following relationships “backward”


foreign-key model instance 는 Manaer 에 접근할수있다.  Manager 는 ForeignKey 를 가지고 있는 model 의 모든 instance 를 반환한다.

(즉, 어떤 model (Blog)에서 자신을 foreign key로 가지고 있는 모델(Entry)에 접근하기위해 Manager 이용하면 된다.)


Manager 명명법 : FOO_set   (단, FOO소문자 source model name)

Manager  : QuerySet 반환


Example:

>>> b = Blog.objects.get(id=1)
>>> b.entry_set.all() # Returns all Entry objects related to Blog.

# b.entry_set is a Manager that returns QuerySets.
>>> b.entry_set.filter(headline__contains='Lennon')
>>> b.entry_set.count()


Using a custom reverse manager




Many-to-many relationships


"reverse" model 은  소문자 original model name + '_set' 사용한다.

( reverse one-to-many relationships 과 같다 )


e = Entry.objects.get(id=3)
e.authors.all() # Returns all Author objects for this Entry.
e.authors.count()
e.authors.filter(name__contains='John')

a = Author.objects.get(id=5)
a.entry_set.all() # Returns all Entry objects for this Author.



One-to-one relationships



How are the backward relationships possible?


다른 ORM 들은 양쪽에서 relationships 을 정의 하지만, 장고는 한쪽에서만 relationship 을 정의한다.


Queries over related objects


For example, if you have a Blog object b with id=5, the following three queries would be identical:

Entry.objects.filter(blog=b) # Query using object instance
Entry.objects.filter(blog=b.id) # Query using id from instance
Entry.objects.filter(blog=5) # Query using id directly




반응형
Posted by 자유프로그램
,
반응형

R markdown Slidy 에 rCharts 결과 그래프 넣기


환경 : winodows 7 32bit, R 3.1.1, RStudio v0.98.1081


참고 :  https://gist.github.com/ramnathv/1fcf50751e461b9192ac




다음과 같은 양식으로 R markdon 에 입력하면 된다.

-- 즉, 결과물을 html 파일로 저장하고, iframe 에서 불러오는 형식으로 하면 성공!


```
{r}
require(rCharts)
r2 <- rPlot(mpg ~ wt, data = mtcars, type = 'point')
r2$save('test.html', cdn = TRUE)
```


	





반응형

'기타' 카테고리의 다른 글

tistory 에서 mathjax 사용하기  (0) 2015.01.05
windows 에서 elasticsearch 설치하기  (0) 2015.01.02
git 설치 및 사용하기  (0) 2014.12.12
R markdown 사용법  (0) 2014.12.05
R -- rCharts 설치 실행하기  (0) 2014.10.25
Posted by 자유프로그램
,
반응형

R -- rCharts 설치 실행하기


환경 : R 3.1.1, windows 7 64bit


참조 : http://ramnathv.github.io/rCharts/

         http://www.rstudio.com/products/rpackages/devtools/

         rCharts Documentation release 0.1.0 




홈페이지에 나온대로 설치 시작했으나, 에러 발생함.





< 해결책 > 


http://www.rstudio.com/products/rpackages/devtools/



> install.packages("devtools")

> require(devtools)

> install_github('rCharts', 'ramnathv')


# 팩키지 설치 후 부터는 아래만 시행하면 됨.

> require(rCharts)

> names(iris) = gsub("\\.", "", names(iris))



     참고:  gsub("\\.", "", names(iris)) 의미 !

             -- 문자열 치환 함수.      http://www.rdocumentation.org/packages/base/functions/grep

             -- names(iris) 의 결과 text 중에서  pattern('.') 에 match 하는 모든 것을 '' 으로 바꿔라!

                   -> 즉, 글자중 . 없애기

 


           



> rPlot(SepalLength ~ SepalWidth | Species, data = iris, color = 'Species', type = 'point')











반응형

'기타' 카테고리의 다른 글

tistory 에서 mathjax 사용하기  (0) 2015.01.05
windows 에서 elasticsearch 설치하기  (0) 2015.01.02
git 설치 및 사용하기  (0) 2014.12.12
R markdown 사용법  (0) 2014.12.05
R markdown Slidy 에 rCharts 결과 그래프 넣기  (0) 2014.10.27
Posted by 자유프로그램
,